2

I want to send 'username' using Selenium python, for the following html:

<div class="entryforms-elements">    
    <input id="entryforms-control-element" class="entryforms-element-text" type="text" autocomplete="off"></input>    
</div>

But none of the following method worked:

browser.find_element_by_xpath('//input[@id="entryforms-control-element"]').send_keys('username')  

browser.find_element_by_id('entryforms-control-element').send_keys('username')  

browser.find_element_by_class_name('entryforms-element-text').send_keys('username')     

Please help me!

3
  • are you waiting for sufficient amount of time so that your element on the page loads completely ? Commented Feb 20, 2014 at 4:16
  • Once you create a driver instance use this to wait for sufficient amount of time self.driver.implicitly_wait(20). Try this probably it will solve the issue (use the id to find the element) Commented Feb 20, 2014 at 4:19
  • @user3235542 can you post the error? I don't understand if the element selected is wrong or if your browser doesn't find the element because you call it before that it's loaded Commented Nov 24, 2016 at 16:56

3 Answers 3

2

You might want to check the size of the found element to be sure you are actually locating something.

If you are using firefox this might be getting in the way: selenium webdriver is clearing out fields after sendKeys had previously populated them

Or some javascript might be munging the field after your keys are sent (maybe some js firing after page load).

You also might try calling click() first and then sending the keypresses -- perhaps that will help focus the element if it's the issue mentioned above or something similar.

Sign up to request clarification or add additional context in comments.

Comments

0

Are you sure that the select by Xpatch is correct?

in my opinion should be something like that:

browser.find_element_by_xpath(".//*[@id='entryforms-control-element']")

in every case just to be sure is better you clean and then you introduce your input

browser.find_element_by_xpath(".//*[@id='entryforms-control-element']").clear()
browser.find_element_by_xpath(".//*[@id='entryforms-control-element']").send_keys('username')

in any case I advice you to use Firefox with the plugin firebug and firepath to know for sure the correct xpath of the elements

Comments

-1

Jump on your browser developer tools and check how long it takes the element to load in the network tab. Then set a wait in your code between the load and element find based on this information.

2 Comments

This should be comment
use this in comment not as answer

Your Answer

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