Im trying to trigger mouse over event using move_to_element in ActionChains, Couldn't get it working. Any help is appreciated. Thanks.
Selenium's Python Module is built to perform automated testing with Python. ActionChains are a way to automate low-level interactions such as mouse movements, mouse button actions, keypress, and context menu interactions. This is useful for doing more complex actions like hover over and drag and drop.
Web Drivers for Using Selenium With PythonSelenium requires a web driver, which will help it interface with the browser that you want to run your tests on. For example, the Firefox browser uses a geckodriver, which you need to install in the right path. The path can be /usr/bin or /usr/local/bin.
Selenium clicks fail when an element is not attached to the current page. Re-find the element if the previously found element has been detached.
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(drivers).move_to_element(drivers.find_element_by_id('element_id')).click().perform()
if you want to select any value,
menu1 = drivers.find_element_by_xpath('html/path/of/select/box')
sub_menu0 = drivers.find_element_by_xpath('html/path/of/selected/option')
clickon = drivers.find_element_by_xpath(path/of/option/where/you/want/to/click)
action = ActionChains(drivers)
action.move_to_element(menu1)
action.move_to_element(sub_menu0)
action.click(clickon)
action.perform()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With