1
我正在考虑用PhantomJS
(或htmlunit
)之类的无头浏览器替代Firefox,以便与selenium
进行网页抓取活动。Selenium的clickAt命令是否适用于无头浏览器?
我认为在硒中的clickAt
命令取决于页面图形渲染,并且它不会在PhantomJS
中工作。任何人都可以证实这一点?
我正在考虑用PhantomJS
(或htmlunit
)之类的无头浏览器替代Firefox,以便与selenium
进行网页抓取活动。Selenium的clickAt命令是否适用于无头浏览器?
我认为在硒中的clickAt
命令取决于页面图形渲染,并且它不会在PhantomJS
中工作。任何人都可以证实这一点?
这为我工作(在Python 3.5):
from selenium import webdriver
import time
if __name__ == '__main__':
driver = webdriver.PhantomJS('<YourPathtoPhantom>')
driver.set_window_size(1400, 1000)
driver.get("http://www.google.com")
el = driver.find_element_by_name('btnI')
action = webdriver.common.action_chains.ActionChains(driver)
action.move_to_element_with_offset(el, 5, 5)
action.click()
action.perform()
time.sleep(2)
driver.save_screenshot('screen.png')