Gavin Jones Gavin Jones - 3 months ago 13
HTML Question

Selenium Python cannot select Element on ConnectWise Login Page

Hi I am trying to select the Company Box on the Connectwise login page to automate a login.

However I have trouble even selecting the Company Field.

enter image description here

The Element that needs selecting:

<input class="loginTextBox loginTextBox-watermark" type="text" autocomplete="off" autocorrect="off" autocapitalize="off"/>


What I have tried:

Tried XPATH:

company_field = driver.find_element_by_xpath("/x:html/x:body/x:div[6]/x:div/x:table/x:tbody/x:tr[1]/x:td/x:table/x:tbody/x:tr[2]/x:td/x:table/x:tbody/x:tr[1]/x:td/x:table/x:tbody/x:tr/x:td[2]/x:table/x:tbody/x:tr[1]/x:td/x:input")


Stack Trace:


selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression /x:html/x:body/x:div[6]/x:div/x:table/x:tbody/x:tr1/x:td/x:table/x:tbody/x:tr[2]/x:td/x:table/x:tbody/x:tr1/x:td/x:table/x:tbody/x:tr/x:td[2]/x:table/x:tbody/x:tr1/x:td/x:input because of the following error:


Tried Class Selection:

company_field = driver.find_element_by_class_name("loginTextBox loginTextBox-watermark")


Stack Trace:


selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Compound class names not permitted


Tried CSS:

driver.find_element_by_css_selector(".loginTextBox loginTextBox-watermark[type='text']").click()


Stack Trace:


selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".loginTextBox loginTextBox-watermark[type='text']"}


HTML Source of Page:

<document>
<html>
<head>
<body style="background-color: #F2F2F2; margin: 0px; padding: 0px;" ondragover="window.event.returnValue=false;">
<iframe id="__gwt_historyFrame" style="position:absolute;width:0;height:0;border:0" tabindex="-1" src="javascript:''"/>
<script src="common/scripts/cw.js?v=201561" type="text/javascript"/>
<script src="common/scripts/cw.io.js?v=201561" type="text/javascript"/>
<script language="javascript" type="text/javascript"> function checkSsl() { if (document.location.protocol != "https:" && document.location.host.indexOf("localhost") == -1 && document.location.href.indexOf("dotnet") == -1) { cw.io.jsonCall("login/IsSslRequired.rails", { 'onsuccess': function (data) { if (data.Data == true) { var url = "https://" + document.location.host + document.location.pathname + document.location.search + document.location.hash; document.location.href = url; } } }); } } cw.ui.createInitialLoadingNode(); checkSsl(); document.writeln("<script type='text/javascript' language='javascript' src='com.connectwise.psa/com.connectwise.psa.nocache.js'></scr" + "ipt>"); function dragover(e) { return false; } </script>
<div id="cw-loading" class="cw-loading">
<script src="com.connectwise.psa/com.connectwise.psa.nocache.js" language="javascript" type="text/javascript"/>
<iframe id="com.connectwise.psa" src="javascript:""" style="position: absolute; width: 0px; height: 0px; border: medium none; left: -1000px; top: -1000px;" tabindex="-1"/>
<div style="display: none;" aria-hidden="true"/>
<div style="position: absolute; z-index: -32767; top: -20cm; width: 10cm; height: 10cm; visibility: hidden;" aria-hidden="true"/>
<div style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div class="GHN3134DCB" style="position: absolute; left: 0px; top: 0px; display: block; width: 1366px; height: 659px;"/>
<div class="GHN3134DJB" style="left: 435px; top: 163px; border-width: 0px; z-index: 555555555; position: absolute; overflow: visible; background-color: transparent;">
<div class="popupContent">
<table cellspacing="0" cellpadding="0" style="">
<tbody>
<tr>
<td align="left" style="vertical-align: top;">
<table class="GHN3134DK5I" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<tr>
<td align="left" style="vertical-align: top;">
<table class="GHN3134DJ5I" cellspacing="0" cellpadding="0" style="display: block;">
<tbody>
<tr>
<td align="left" style="vertical-align: top;">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td align="left" style="vertical-align: top;">
<td align="left" style="vertical-align: top;">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td align="left" style="vertical-align: top;">
<input class="loginTextBox loginTextBox-watermark loginTextBox-hightlight" type="text" autocomplete="off" autocorrect="off" autocapitalize="off"/>
</td>
</tr>
<tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<tr>
<tr>
<tr>
<tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
</document>


Would appreciate any help?

Thanks for your time.

Answer

selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression /x:html/x:body/x:div[6]/x:div/x:table/x:tbody/x:tr1/x:td/x:table/x:tbody/x:tr[2]/x:td/x:table/x:tbody/x:tr1/x:td/x:table/x:tbody/x:tr/x:td[2]/x:table/x:tbody/x:tr1/x:td/x:input

This error occurred because provided xpath syntactically incorrect.

selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Compound class names not permitted

This error occurred because selenium doesn't support compound class to locate an element.

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".loginTextBox loginTextBox-watermark[type='text']"}

This error occurred because you are locating incorrect element. According to locator it would be try to locate <loginTextBox-watermark> element which attribute type has value text and should be descendant of an element which has class attribute value loginTextBox which is incorrect.

So basically your all provided locators are syntactically or logically incorrect, you should try using correct css_selector locator as below :-

driver.find_element_by_css_selector("input.loginTextBox.loginTextBox-watermark.loginTextBox-hightlight[type='text']")

Or if <table> class name GHN3134DJ5I is unique and fixed, you can try also as :-

driver.find_element_by_css_selector("table.GHN3134DJ5I input.loginTextBox.loginTextBox-watermark.loginTextBox-hightlight[type='text']")

Css Selector reference : to learn more about css_selector follow this reference

Xpath reference : : to learn more about xpath follow this reference