在 Selenium 3.7.0 版无头驱动程序 phantomjs 2.1 版上启用 Cookie

问题描述

我正在尝试使用已弃用的 selenium 与无头驱动程序一起运行 phantomjs,因为它在无头模式下接受经过身份验证的代理。

我正在尝试登录亚马逊网站,但无法点击 continue 按钮。

加载页面源状态我必须启用 cookie:

<div id="auth-cookie-warning-message" class="a-Box a-alert a-alert-warning"><div class="a-Box-inner a-alert-container"><h4 class="a-alert-heading">Please Enable Cookies to Continue</h4><i class="a-icon a-icon-alert"></i><div class="a-alert-content">

我的代码如下:

headers = { 'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:63.0) Gecko/20100101 Firefox/63.0",'Connection': 'keep-alive'
}
for key,value in headers.items():
    webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.customHeaders.{}'.format(key)] = value
webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.settings.userAgent'] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:63.0) Gecko/20100101 Firefox/63.0"
CHROMEDRIVER_PATH = './phantomjs-2.1.1-linux-x86_64/bin/phantomjs'
WINDOW_SIZE = "1920,1080"

proxy = '45.95.99.20:7580'

service_args=['--ignore-ssl-errors=true','--ssl-protocol=any','--proxy={}'.format(proxy),'--proxy-type=http','--proxy-auth={}:{}'.format(proxy_user,proxy_pass)]
service_args.append('--ignore-ssl-errors=true')
service_args.append('--web-security=no')
driver = webdriver.PhantomJS(
    executable_path=CHROMEDRIVER_PATH,service_args=service_args
    )
driver.get(url)
username_input = driver.find_element_by_css_selector("input[name='email']")
username_input.send_keys(login)

login_button=driver.find_element_by_id('continue')
login_button.click()

设置如下

Phantomjs 2.1
Selenium 3.7.0
Ubuntu 18.04

点击 continue 时,什么也没有发生。

我怎样才能克服这个问题并启用 cookie?

enter image description here

解决方法

使用 webdriver.ActionChains() insted of click()

解决了
action = webdriver.ActionChains(driver)
login_button=driver.find_element_by_id('continue')
action.move_to_element(login_button).click().perform()