In Selenium, how to handle InvalidSelectorException while log in website

Viewed 1605

I'm trying to log in website with selenium. This is the code that I made.

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://abcde.com")

assert "xxx" in driver.title
user = driver.find_element_by_css_selector("#ctl00_MasterHeaderPlaceHolder_ctl00_userNameTextbox")
user.clear()
user.send_keys("username")

pwd = driver.find_element_by_css_selector("#ctl00$MasterHeaderPlaceHolder$ctl00$passwordTextbox")
pwd.clear()
pwd.send_keys("mypassword")
pwd.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()

When I run this code, InvalidSelectorException has occurred.

raise exception_class(message, screen, stacktrace) selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: An invalid or illegal selector was specified (Session info: chrome=59.0.3071.115) (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 4.4.0-83-generic x86_64)

I've attached png file for your convenience. enter image description here This is the page source in the website.

<input name="ctl00$MasterHeaderPlaceHolder$ctl00$userNameTextbox" type="text" value="Username" id="ctl00_MasterHeaderPlaceHolder_ctl00_userNameTextbox" OnClick="UsernameBehaviour(&quot;click&quot;, &quot;ctl00_MasterHeaderPlaceHolder_ctl00_userNameTextbox&quot;, &quot;Username&quot;);" OnFocus="UsernameBehaviour(&quot;focus&quot;, &quot;ctl00_MasterHeaderPlaceHolder_ctl00_userNameTextbox&quot;, &quot;Username&quot;);" OnBlur="UsernameBehaviour(&quot;blur&quot;, &quot;ctl00_MasterHeaderPlaceHolder_ctl00_userNameTextbox&quot;, &quot;Username&quot;);" />            
<input name="ctl00$MasterHeaderPlaceHolder$ctl00$passwordTextbox" type="password" id="ctl00_MasterHeaderPlaceHolder_ctl00_passwordTextbox" OnBlur="PasswordBehaviour(&quot;ctl00_MasterHeaderPlaceHolder_ctl00_passwordTextbox&quot;, &quot;ctl00_MasterHeaderPlaceHolder_ctl00_tempPasswordTextbox&quot;, 1);" style="display:none" />
<input name="ctl00$MasterHeaderPlaceHolder$ctl00$tempPasswordTextbox" type="text" value="Password" id="ctl00_MasterHeaderPlaceHolder_ctl00_tempPasswordTextbox" OnClick="PasswordBehaviour(&quot;ctl00_MasterHeaderPlaceHolder_ctl00_passwordTextbox&quot;, &quot;ctl00_MasterHeaderPlaceHolder_ctl00_tempPasswordTextbox&quot;, 2);" OnFocus="PasswordBehaviour(&quot;ctl00_MasterHeaderPlaceHolder_ctl00_passwordTextbox&quot;, &quot;ctl00_MasterHeaderPlaceHolder_ctl00_tempPasswordTextbox&quot;, 2);" />

I have attached png file for the convenience. enter image description here

As you can see, there are two input box related password. When I click password input tag, javascript seems to do something. But I'm not sure.

I would like to know the reason and solution.

Thanks for your time.

Please help me.

1 Answers
Related