Selenium Python cannot select Element on ConnectWise Login Page
<p>Hi I am trying to select the Company Box on the Connectwise login page to automate a login.</p>

<p>However I have trouble even selecting the Company Field.</p>

<p><a href="http://i.stack.imgur.com/Z5en9.png" rel="nofollow"><img src="http://i.stack.imgur.com/Z5en9.png" alt="enter image description here"></a></p>

<p>The <strong>Element</strong> that needs selecting:</p>

<pre><code>&lt;input class="loginTextBox loginTextBox-watermark" type="text" autocomplete="off" autocorrect="off" autocapitalize="off"/&gt;
</code></pre>

<p><strong>What I have tried:</strong></p>

<p>Tried <strong>XPATH</strong>: </p>

<pre><code>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")
</code></pre>

<p>Stack Trace:</p>

<blockquote>
  <p>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:tr<a href="http://i.stack.imgur.com/Z5en9.png" rel="nofollow">1</a>/x:td/x:table/x:tbody/x:tr[2]/x:td/x:table/x:tbody/x:tr<a href="http://i.stack.imgur.com/Z5en9.png" rel="nofollow">1</a>/x:td/x:table/x:tbody/x:tr/x:td[2]/x:table/x:tbody/x:tr<a href="http://i.stack.imgur.com/Z5en9.png" rel="nofollow">1</a>/x:td/x:input because of the following error:</p>
</blockquote>

<p>Tried <strong>Class Selection</strong>: </p>

<pre><code>company_field = driver.find_element_by_class_name("loginTextBox loginTextBox-watermark")
</code></pre>

<p>Stack Trace:</p>

<blockquote>
  <p>selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Compound class names not permitted</p>
</blockquote>

<p>Tried <strong>CSS</strong>:</p>

<pre><code>driver.find_element_by_css_selector(".loginTextBox loginTextBox-watermark[type='text']").click()
</code></pre>

<p>Stack Trace:</p>

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

<p><strong>HTML Source of Page:</strong></p>

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

<p>Would appreciate any help?</p>

<p>Thanks for your time.</p>

<blockquote>
  <p>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</p>
</blockquote>

<p>This error occurred because provided <code>xpath</code> syntactically incorrect.</p>

<blockquote>
  <p>selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Compound class names not permitted</p>
</blockquote>

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

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

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

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

<pre><code>driver.find_element_by_css_selector("input.loginTextBox.loginTextBox-watermark.loginTextBox-hightlight[type='text']")
</code></pre>

<p>Or if <code>&lt;table&gt;</code> class name <code>GHN3134DJ5I</code> is unique and fixed, you can try also as :-</p>

<pre><code>driver.find_element_by_css_selector("table.GHN3134DJ5I input.loginTextBox.loginTextBox-watermark.loginTextBox-hightlight[type='text']")
</code></pre>

<p><strong>Css Selector reference</strong> : to <a href="http://www.w3schools.com/cssref/css_selectors.asp" rel="nofollow">learn more about <code>css_selector</code> follow this reference</a></p>

<p><strong>Xpath reference</strong> :  : to <a href="http://www.w3schools.com/xsl/xpath_syntax.asp" rel="nofollow">learn more about <code>xpath</code> follow this reference</a></p>

python html selenium