简体   繁体   English

使用Splinter + PhantomJS(Python)访问表单

[英]Accessing a form with Splinter + PhantomJS (Python)

I'm trying to fill in the username and password box on this site: http://www.youwager.eu/welcome/ 我正在尝试在此站点上填写用户名和密码框: http : //www.youwager.eu/welcome/

Here's the relevent html: 这是相关的html:

<input type="text" class="form-control" name="customerid" id="customerid" placeholder="Account Number">

A simple browser.fill('customerid', login) works when using firefox, but I can't get phantomJS to interact with the element. 使用firefox时,可以使用一个简单的browser.fill('customerid',login),但是我无法让phantomJS与该元素进行交互。 It throws the following error: 它引发以下错误:

<class 'selenium.common.exceptions.InvalidElementStateException'> , InvalidElementStateException()

Code to reproduce the issue: 重现此问题的代码:

from splinter import Browser
browser=Browser('phantomjs') #=Browser() uses firefox, and works
browser.visit('http://www.youwager.eu/welcome')
browser.fill('customerid', login)

Using Splinter 0.5.4, Selenium 2.43.0, PhantomJS 1.9.7.0 使用Splinter 0.5.4,Selenium 2.43.0,PhantomJS 1.9.7.0

The problem is that PhantomJS has a viewport size of 400x300 by default and the page changes its layout for smaller widths in which the field is not visible and because of that not interactible through the WebDriver API. 问题在于,PhantomJS默认情况下的视口大小为400x300,并且页面将其布局更改为较小的宽度,在该宽度中该字段不可见,并且因为该字段无法通过WebDriver API进行交互。

You have two options. 您有两个选择。 Either you change your script to take the different page layout due to media queries into account or you change the browser window size through code. 您可以更改脚本以考虑到媒体查询而采用不同的页面布局,或者通过代码更改浏览器窗口的大小。

With Selenium this is done like this (from here ): 使用Selenium可以做到这一点(从此处开始 ):

driver.set_window_size(1234, 987)

According to the code ( 1 , 2 ) it seems you can do this like this: 据代码( 12 ),似乎可以做到这一点是这样的:

from splinter import Browser
browser=Browser('phantomjs')
browser.driver.set_window_size(1234, 987)
browser.visit('http://www.youwager.eu/welcome')
browser.fill('customerid', login)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM