selenium not finding the element


I am trying to select a textbox and enter text in it through selenium web driver. The html is as follows:

    <input name="mLayout$ctl00$ctl00$6$16$ctl00$Database" type="text" value="Enter database name" maxlength="175" size="26" id="mLayout_ctl00_ctl00_6_16_ctl00_Database" accesskey="s" title="Go search this database" class="InputContent GhostText" onfocus="SearchBoxOnFocus(&#39;mLayout_ctl00_ctl00_6_16_ctl00_Database&#39;);" onkeypress="if(!__TextBoxOnKeyPress(&#39;mLayout$ctl00$ctl00$6$16$ctl00$GoButton&#39;,event.which)) { return false; }" />&nbsp;<input type="image" name="mLayout$ctl00$ctl00$6$16$ctl00$GoButton" id="mLayout_ctl00_ctl00_6_16_ctl00_GoButton" title="Go search database" src="" alt="Go search database" align="absmiddle" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;mLayout$ctl00$ctl00$6$16$ctl00$GoButton&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" style="height:18px;width:21px;border-width:0px;" />

I've tried the following

dbElement = WebDriverWait(driver, 20).until(lambda x : x.find_element_by_id("mLayout_ctl00_ctl00_6_16_ctl00_Database"))

Is there something special about the $ and _ characters is the fields? Why can't selenium locate these elements?

10/20/2012 9:40:31 PM

Accepted Answer

Solution: make sure you are in the right window. In the step before this one, I had clicked on a link that opened a new window, and I had assumed that that window would automatically be the active one.

To see which windows are available, run:


This returns a list. Note the window you want to change to, with index i. To then change the window, run:

11/5/2012 10:24:17 PM

the idea is in following. IF you are not able to located element by the whole name I would try to locate it by the part of the name. So i would try this approach:

Attribute A of element where A contains 't'

xpath: //E[contains(@A,'t')]/@A ⌦ {Se: //E[contains(@A,'t')]@A }

css: NA {Se: css=E[A*='t']@A } taken here

So it be something


in that way i usually verify in cases I'm not confident about my locator: enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow