link http://www.babylegs.com
My code:
class TestClassMy(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
def test1(self):
driver = self.driver
driver.get('http://www.babylegs.com')
driver.maximize_window()
element_to_select = driver.find_element_by_xpath(".//*[@id='nav']/ol/li[5]/a") #d.send_keys(Keys.NULL)
actions = ActionChains(driver)
element_to_select.click_and_hold(element_to_select).perform()
def tearDown(self):
self.driver.close()
if __name__ == '__main__':
unittest.main()
Assuming your browser is Firefox, the Python code would look like this:
driver = webdriver.Firefox(executable_path=driver_path)
action = webdriver.ActionChains(driver)
element = driver.find_element_by_id('your-id') # or your another selector here
action.move_to_element(element)
action.perform()
If you have already moved your cursor to an element and want to re-position it relatively, you can use:
action.move_by_offset(10, 20) # 10px to the right, 20px to bottom
action.perform()
or even shorter:
action.move_by_offset(10, 20).perform()
More documentation is here: https://selenium-python.readthedocs.io/api.html
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