How do you click on an element which is hidden using Selenium WebDriver?

前端 未结 3 1709
臣服心动
臣服心动 2020-12-15 08:43

I have a web application which I am automating using WebDriver and Python.

The issue is that there is a menu something like this

相关标签:
3条回答
  • 2020-12-15 09:32

    Grab the element you want to click:

    # Or using xparth or something
    element = driver.find_element_by_css_selector(css_selector)
    

    Click it using javascript:

    driver.execute_script("$(arguments[0]).click();", element)
    

    NOTE: I'm using jQuery otherwise select it native with javascript

    0 讨论(0)
  • 2020-12-15 09:33

    If your application uses jQuery you can use it to specify a target element which will simplify your work. E.g.

    $('.targetClass')
    
    0 讨论(0)
  • 2020-12-15 09:47

    You can use JavaScriptExecutor

    For Eg. - document.getElementsByClassName('post-tag')[0].click();

    Issue that JS via JavaScriptExecutor

      (JavascriptExecutor(webdriver)).executeScript("document.getElementsByClassName('post-tag')[0].click();");
    
    0 讨论(0)
提交回复
热议问题