0

enter image description here

I already got the Xpath, but when I'm trying send keys there is error :

 Error
 Traceback (most recent call last):
 File "C:\Users\Admin\PycharmProjects\Belajar1\Register.py", line 23, in test_register
self.email = self.driver.find_element_by_xpath(".//*[@id='email']").send_keys("dssdf")
 File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 334, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': typing})
 File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 460, in _execute
return self._parent.execute(command, params)
 File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in execute
self.error_handler.check_response(response)
 File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 188, in check_response
raise exception_class(message, screen, stacktrace)

Help please. I am new in selenium with python.

8
  • This looks like a pop up box or a frame. Have you switched to the frame and then tried to enter the code? Commented Feb 20, 2016 at 14:26
  • yes, I already made code : switch to frame but didn't work.
    – Santi
    Commented Feb 20, 2016 at 14:27
  • Wait. It's not a pop- up. have you tried using the actions class to jump to this element. I think this is a hover over menu, which can be solved by using Actions. Commented Feb 20, 2016 at 14:29
  • do you mean using Actionchains?
    – Santi
    Commented Feb 20, 2016 at 14:53
  • Yes. Precisely. Commented Feb 20, 2016 at 14:53

2 Answers 2

1

As @FDM mentioned the $x("//*[@id='email']") will find 2 matching elements. So you need to build a locator that is more unique/precise. If you search it in Firebug or any other console you'll notice that it yields two matching nodes.

I'm not sure in Python how it should be, but I tried this in Java using the following CSS selector and it worked.

driver.findElement(By.cssSelector("div[id=top-user-menu-wrapper] input[id=email]")).sendKeys("test");
2
  • thank you @ilm @FDM it's work. python : self.email = self.driver.find_element_by_css_selector("div[id=top-user-menu-wrapper] input[id=email]")
    – Santi
    Commented Feb 22, 2016 at 6:20
  • @Santi Your Welcome!
    – ilm
    Commented Feb 23, 2016 at 2:56
0

Try executing the following command in Chrome (F12 < Console):

$x("//*[@id='email']")

You will see that the page has two elements with this identifier (which is, in fact, not conforming to the meaning of id).

When the email field is visible, as in your screenshot, it is actually the second email field that you see. But Selenium finds the first element which is invisible, and thus your code fails.

Solution: try making your XPath more specific.

3
  • I use path : $x("//*[@id='email']")
    – Santi
    Commented Feb 22, 2016 at 1:20
  • Well... that's probably the problem, if you read my answer carefully. :)
    – FDM
    Commented Feb 22, 2016 at 6:34
  • yes.. after analyze again, i get it.. sorry for my bad.... i am new in automation test. @FDM 😄 😄
    – Santi
    Commented Feb 22, 2016 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.