All notes
Selenium

FAQ

Ref. In the archive, the XPI file is here: org/openqa/selenium/firefox. To install it by pip:

cd selenium-2.45.0
pacman -Ss pip
sudo pacman -S python-pip
pip install setuptools
sudo python setup.py install

# To solve: FirefoxProfile exception Can't load the profile
pip install -U selenium

Install python and selenium

Install for chrome

Developed in collaboration with the Chromium team, ChromeDriver is a standalone server which implements WebDriver's wire protocol.

You need to download the executable driver from: https://sites.google.com/a/chromium.org/chromedriver/downloads, which is named as "chromedriver.exe".

Then all you need is before creating the driver object use the following (already shown in the correct order):

import os
from selenium import webdriver

chromedriver = "/Users/adam/Downloads/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.get("http://stackoverflow.com")
driver.quit()

Maximize window

When the browser window is not large enough for some elements to show, those elements are not clickable. So we would always want to maximize the browser.

Javascript way

StackOverflow.

driver.execute_script("window.moveTo(0,0); window.resizeTo(screen.width, screen.height);")

Driver Options way

ChromeOptions options = new ChromeOptions();
options.AddArgument("--start-maximized");
driver = new ChromeDriver(options);

StackOverflow.

# First instantiate a firefox driver
WebDriver driver = new FirefoxDriver();
# then maximize it
driver.manage().window().maximize();

Zoom in/out

TestingDiaries. The code example below will zoom web page in by 5 levels, zoom out by 1 level and will return to the default zoom level.

public void ZoomExample() throws Exception {
	driver = new FirefoxDriver();
	baseUrl = "https://www.google.co.in";
	driver.get(baseUrl + "/");

	driver.findElement(By.tagName("html")).sendKeys(
			Keys.chord(Keys.CONTROL, Keys.ADD));
	driver.findElement(By.tagName("html")).sendKeys(
			Keys.chord(Keys.CONTROL, Keys.ADD));
	driver.findElement(By.tagName("html")).sendKeys(
			Keys.chord(Keys.CONTROL, Keys.ADD));
	driver.findElement(By.tagName("html")).sendKeys(
			Keys.chord(Keys.CONTROL, Keys.ADD));
	driver.findElement(By.tagName("html")).sendKeys(
			Keys.chord(Keys.CONTROL, Keys.ADD));
	driver.findElement(By.tagName("html")).sendKeys(
			Keys.chord(Keys.CONTROL, Keys.SUBTRACT));
	driver.findElement(By.tagName("html")).sendKeys(
			Keys.chord(Keys.CONTROL, "0"));
}
StackOveflow for python.