Python Selenium`move_by_offset`不起作用 [英] Python Selenium `move_by_offset` doesn't work
本文介绍了Python Selenium`move_by_offset`不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Python Selenium调用简单的滚动操作不起作用:
Calling simple scrolling action with Python Selenium doesn't work:
driver = webdriver.Chrome()
driver.get('https://www.wikipedia.org/')
time.sleep(2)
actions = ActionChains(driver)
actions.move_by_offset(500, 500).perform()
例如移动到元素的功能,有效确定并滚动":
For example function with moving to element, works Ok and Do scroll:
driver = webdriver.Chrome()
driver.get('https://www.wikipedia.org/')
time.sleep(2)
element = driver.find_element_by_css_selector(<Something>)
actions = ActionChains(driver)
actions.move_to_element(element).perform()
调用移动到具有偏移的元素,不再起作用:
Calling moving to element with offset, doesn't work again:
driver = webdriver.Chrome()
driver.get('https://www.wikipedia.org/')
time.sleep(2)
element = driver.find_element_by_css_selector(<Something>)
actions = ActionChains(driver)
actions.move_to_element_with_offset(element, 500, 500).perform()
任何原因吗?
推荐答案
在移动鼠标后尝试等待几秒钟.例如,以下代码可在我的CentOS7.3主机中获取屏幕截图.
Try to wait some seconds after moving mouse. For example, the following code to get screen captures in my CentOS7.3 host worked for me.
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument("--window-size=720,480")
chrome_options.add_argument('--no-sandbox')
driver = webdriver.Chrome('/usr/bin/chromedriver', chrome_options=chrome_options, service_args=['--verbose', '--log-path=/tmp/chromedriver.log'])
driver.get(url)
time.sleep(6)
ActionChains(driver).move_by_offset(50, 50).perform()
time.sleep(2)
filename="/tmp/Screenshots/uuid.png"
driver.save_screenshot(filename)
这篇关于Python Selenium`move_by_offset`不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文