Rishi
Rishi

Reputation: 2017

Selenium webdriver without any Desktop browser

I am using selenium. I have the following code:

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
browser.get("http://www.mysite.com")
x = browser.find_elements_by_xpath("//div[@id='containeriso3']/div/a[1]")
hrefs = [i.get_attribute('href') for i in x]

Now, this works.

But I want to do this is on a server which runs on ubuntu command line. This means I cannot use this

browser = webdriver.Firefox()

in my code. What alternative can be used to this through command line?

Upvotes: 1

Views: 3509

Answers (3)

Alexander Bezrodniy
Alexander Bezrodniy

Reputation: 8804

I think you can also try to use ghost driver that is based on phantomjs:

https://github.com/detro/ghostdriver, or you can also try to run usual firefox driver on Xvfb.

It depends on what you need.

Upvotes: 0

You can use HtmlUnitDriver which is headless browser based on Rhino javascript engine.

http://code.google.com/p/selenium/wiki/HtmlUnitDriver

Upvotes: 4

so cal cheesehead
so cal cheesehead

Reputation: 2573

If your Ubuntu server and your desktop are on the same network use Selenium Grid. Your code will start on the Linux server and your tests will be executed on your desktop.

Take a look at the following link:

http://code.google.com/p/selenium/wiki/Grid2

The examples are in Java but I'm sure you can adapt them to Python or at least get the idea of what you need to do.

Upvotes: 1

Related Questions