Keep bumping into the same problem: when I use Selenium (Python), I often need to find the element to send_keys() to. E.g. on ebay front webpage, need to search for some item.
Each time I end up tring all the classes/frames around what I need (sometimes with ChroPath) and one of them works. Is there a simpler and more systematic way to find the element corresponding to search tab to send keys to?
2
Answers
Well one thing you could try is using
hasattr
method to check if the element has a particular attribute or not. From the official documentation abouthasattr
No, you shouldn’t try to invoke
send_keys()
on random elements on a webpage, e.g. ebay homepage.Ideally, the WebElements with whom you would interact or invoke
send_keys()
should be part of your tests and should also be a part of the Test Plan.While you execute your tests, in the due coarse you may encounter different errors when
send_keys()
is being invoked. You have a to address the issues as they show up as per the prevailing condition of the HTML DOM.References
You can find a couple of relevant discussions on
send_keys()
in: