启用Cookie在Phantomjs +硒 [英] enable cookies in Phantomjs + selenium

查看:1300
本文介绍了启用Cookie在Phantomjs +硒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要登入amazons3(网址为:「 https:// console」) .aws.amazon.com / iam / home?#security_credential ')在我的armv7板上。我使用phantom2.0.1从 here and selenium2.45.0。

I want to login in amazons3 (with the url:'https://console.aws.amazon.com/iam/home?#security_credential') on my armv7 board.I used phantom2.0.1 from here and selenium2.45.0.

我可以成功打开网站,但是当我在填写用户名和密码,网站跳转到一个错误页面,显示请启用Cookie继续。所以我想知道如何在selenium中启用phantomjs的cookies。在我的ubuntu12.04中,使用合适的phantomjs版本,我可以成功

I can open the website successfully, but when I doing 'submit' after filling the username and password, the website jump to an error page which shows ‘Please Enable Cookies to Continue’. So I wonder how to enable cookies for phantomjs in selenium.In my ubuntu12.04 with suitable version of phantomjs, I can succeed

我的代码如下: p>

Part of my code is below:

def __init__(self,username,password,login_url,width=1151,height=629):
    self.username = username
    self.password = password
    self.login_url = login_url
    dcap = dict(DesiredCapabilities.PHANTOMJS)  
    dcap["phantomjs.page.settings.userAgent"] = ( "Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) Phantomjs/2.0.1 Safari/534.34" )  
    self.driver = webdriver.PhantomJS(executable_path='/bin/phantomjs',desired_capabilities=dcap,service_args=['--ssl-protocol=any','--ignore-ssl-errors=true'])
    self.driver.set_window_size(width,height)

def _login_system(self):
    try:
        self.driver.get(self.login_url)
        print self.driver.page_source#I can success here
        WebDriverWait(self.driver, 30).until(lambda driver : self.driver.find_element_by_id("ap_email")).send_keys(self.username)
        WebDriverWait(self.driver, 30).until(lambda driver : self.driver.find_element_by_id("ap_password")).send_keys(self.password)
        WebDriverWait(self.driver, 30).until(lambda driver : self.driver.find_element_by_id("signInSubmit-input")).submit()#failed here and showing Please Enable Cookies to Continue


推荐答案

我找到了答案,
似乎亚马逊不接受phantomjs /(。*)在useragent

I've found the answer, It seems that amazon does not accept "Phantomjs/(..*)" in the useragent

fail:Mozilla / 5.0(Macintosh; Intel Mac OS X)AppleWebKit / 534.34(KHTML,如Gecko)Phantomjs / 2.0.1 Safari / 534.34

fail:Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) Phantomjs/2.0.1 Safari/534.34

OK:Mozilla / 5.0(Macintosh; Intel Mac OS X 10.9 ; rv:36.0)Gecko / 20100101 Firefox / 36.0 WebKit

OK:Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:36.0) Gecko/20100101 Firefox/36.0 WebKit

此外,我在useragent的末尾添加WebKit,因为undefined is not对象( https://github.com/detro/ghostdriver/issues/325 ) )

In addition,I add "WebKit" at the end of the useragent,because of the problem "undefined is not an object"(https://github.com/detro/ghostdriver/issues/325)

此外,我遇到了一个问题raise BadStatusLine(line)(像这样:在这里输入链接描述)。可能是由于selenium和phantomjs的版本中的
所以我使用phantomjs1.9.8(piksel / phantomjs-raspberrypi在github)

What's more,I've met a problem of "raise BadStatusLine(line)"(like here:enter link description here).And it may be caused by the dismatch of the versions of selenium and phantomjs,so I use phantomjs1.9.8 instead(piksel/phantomjs-raspberrypi in github)

对于编译问题,如果你要在arm板上编译,你最好使用交换扩展RAM。

For the compile problem,if you are to compile on an arm board,you'd better use swap to extend the RAM.

这篇关于启用Cookie在Phantomjs +硒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆