Selenium: making it run faster

Most of the timeout issues are due to the speed selenium runs compared to the user’s input. A common practice is to add time.sleep() commands where this happens, but that slows down your app considerably. That is called implicit wait.

A better way to do this is to add a constant polling to the DOM you are waiting to show or the condition on the UI that will tell you you are ready to continue.  See examples of this on:

By removing all implicit waits, and just relying on explicit waits we made our testing app take 5 minutes instead of 30. You can never underestimate the amount of time you can save by sticking to this simple principle.


Selenium: Python webdriver common commands

I keep forgetting and having to look them up:

// Find an element by CSS selector:

driver.find_element_by_css_selector(“.canvas-placard.back .close”).click()

// Assert DOM element not present (by CSS selector):

self.assert_not_present(By.CSS_SELECTOR, “.canvas-placard.front”)

// Assert true or equal, and at the same time get an attribute from a DOM element:

self.assertEqual(“true”, driver.find_element_by_xpath(“//select[@id=’type’]”).get_attribute(“disabled”))

// Sending stuff to input fields:

self.driver.find_element_by_css_selector(“.myselector”).send_keys(“The text to field the input text with”)

// Executing javascript directly:

self.driver.execute_script(“alert(‘hello world’);”)

// Find something by the text on a link:

driver.find_element_by_link_text(“A Selenium Test Action “).click()

// Test if text present / not present:

self.assert_text_not_present(“Something something here”)

self.assertTrue( requestText.index(“some string here”) > -1 )

selenium testing

selenium: python webdriver choosing a select box option

from selenium import webdriver
from import Select
selectBox = Select(driver.find_element_by_id(....))