skip to Main Content

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


  1. 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 about hasattr

    hasattr(object, name) The arguments are an object and a string. The
    result is True if the string is the name of one of the object’s
    attributes, False if not. (This is implemented by calling
    getattr(object, name) and seeing whether it raises an AttributeError
    or not.)

    if hasattr(element, 'send_keys'):
        # do something
    
    Login or Signup to reply.
  2. 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:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search