How do I locate an element from a web click?



  • Python-selenium documentation has examples of locating elements based on id, class, name, xpath, etc.

    How would I go about locating elements based on the click location from the mouse?



  • I think this is what you are trying to do, the below command gets the currently active element (In your case , you will get element where the mouse is blinking )

    elem = driver.switch_to.active_element
    

    and you could also get the web element tag as

    val = elem.get_attribute("outerHTML")
    

    Print the val and you can see the html of the element identified by the click

    print(val)  #this gives the full html of that particular element eg <div id="answer-42436" class="answer" data-answerid="42436" itemprop="suggestedAnswer" itemscope="" itemtype="http://schema.org/Answer">
    

Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2