Selenium - Click at certain position

后端 未结 4 1639
既然无缘
既然无缘 2020-12-08 15:13

Using the Python version of Selenium, is it possible to click some element in the DOM and to specify the coordinates where you want to click it? The Java version has the met

4条回答
  •  既然无缘
    2020-12-08 16:12

    You can perform the task with the Action chains in the python specially with Edge browser:

    from selenium.webdriver import ActionChains
    actionChains = ActionChains(driver)
    button_xpath  = '//xapth...' 
    button = driver.find_element_by_xpath(button_xpath)
    actionChains.move_to_element(button).click().perform()
    

    But sometimes Action chain does not finds the DOM element. Hence better option to use execute scipt in following way:

    button_xpath  = '//xapth...' 
    button = driver.find_element_by_xpath(button_xpath)
    driver.execute_script("arguments[0].click();", button)
    

提交回复
热议问题