python - 在 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?
解决方案
通过使用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()
推荐阅读
- vaadin - 用于字符串数组的 vaadin-grid-filter 不起作用
- mysql - mysql函数变量集不起作用
- php - 可以用多个键做 JSON_EXTRACT 吗?
- mysql - Sequelize 限制和订单不适用于条件查询
- javascript - 如何从 Google Maps API 中的拖动事件中获取自动完成地址?
- arrays - 为什么这个拆分字符串表达式不给我一个数组?
- java - 如何从嵌套的 JSON 中检索值
- oracle - 使用循环获取输出但我不想要多个输出我只需要一个输出
- php - Wordpress 网格显示空条目
- android - 回收站视图中的缓慢滚动