Mcdizzle
Mcdizzle

Reputation: 81

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/

Here's the relevent 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. 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

Upvotes: 1

Views: 1024

Answers (1)

Artjom B.
Artjom B.

Reputation: 61952

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.

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):

driver.set_window_size(1234, 987)

According to the code (1, 2) it seems you can do this like this:

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)

Upvotes: 2

Related Questions