Hot answers tagged

45 votes

How do I close the browser window at the end of a Selenium test?

driver.close() and driver.quit() are two different methods for closing the browser session in Selenium WebDriver. driver.close() - It closes the the browser window on which the focus is set. driver....
14 votes
Accepted

How to send Basic Authentication headers in Selenium?

I've tested using format http://user:pass@host and it works. So in Python (in setUp() of MyClass(unittest.TestCase) class) this should look like: self.base_url = "http://user:pass@host" In Java ...
  • 367
13 votes

How to set browser locale with chromedriver (Python)

Not Working I've tried the --lang=us option, as suggested, but also had no success using the code below. My webpages were still being downloaded with my default language (that's not en). from ...
  • 231
11 votes

How to clear localStorage using selenium and webdriver

If your driver implements WebStorage you can invoke driver.getSessionStorage().clear(); driver.getLocalStorage().clear(); In order to make sure that the driver does implement WebStorage the idiom is ...
8 votes

How install both Python32 and Python33 on OS X for testing with tox?

The installation instructions referenced by @dimitry-cheremushkin have been changed and recommend using pyenv instead. Tox and Pyenv can be used together like this: First we ensure we have pyenv ...
7 votes

Which language to choose for Appium - Python or Java?

Oh Boy! you might start another one of the Java vs Python vs Other language war. These are kind of question which are always answered with preference for a specific language in mind. For me- I would ...
  • 3,540
7 votes
Accepted

Where do Fitnesse fits between unittests and API testing?

Full disclosure: we rely heavily on FitNesse, run many hours worth of FitNesse tests daily in our CI buildbot daily, and I personally wrote both FitNesse tests (using Fit wiki format in browser) and ...
7 votes
Accepted

Pros and cons of python unit testing packages

Nose is no longer maintained: Nose has been in maintenance mode for the past several years and will likely cease without a new person/team to take over maintainership. New projects should ...
  • 11.4k
7 votes
Accepted

Wait until in Select element using selenium

You can use Explicit Wait: An explicit wait is a code you define to wait for a certain condition to occur before proceeding further in the code. OPTION-1: driver.implicitly_wait(10) # seconds ...
  • 6,769
7 votes
Accepted

Check if password field displays masked characters (Selenium + Python)

You are not checking if the password is masked, but if it there is an input of type password. Which is good, because you do not want to test browser behaviour, but the implementation by the developers....
7 votes

Using Python Selenium Not able to perform click operation

Try using JavaScriptExecutor C# IWebElement element = driver.FindElement(By.XPath("//button[@role='button']")); IJavaScriptExecutor jse2 = (IJavaScriptExecutor)driver; jse2.ExecuteScript("arguments[...
6 votes

How to download a file using Selenium's WebDriver?

I made my own version of the downloader, by using an Ajax request and returning the bytes. Has the advantage that it uses the browser directly, so authentication and cookies do not need to be dealt ...
  • 161
6 votes

How to clear localStorage using selenium and webdriver

The answer Peter Masiar gave no longer works. This answer will result in the following exception: Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python....
  • 161
6 votes
Accepted

how to proceed after clicking a link to new page in selenium in python

The problem is that you don't switch to opened window, and webdriver searches for elements in the old page instead of the newly opened one. Solution: String winHandleBefore = driver.getWindowHandle(...
6 votes
Accepted

Test Automation for a website with over 8000 webpages

https://pypi.python.org/pypi/LinkChecker - Python module to build link checkers. Dev status is Production/Stable. There are dozens of other tools like this, in many languages. It makes perfect sense ...
6 votes
Accepted

How to add assertion for blank value?

I think in Python you can check for None or "" on Empty string Some options: self.assertEqual(element.text, None) self.assertEqual(element.text, "") self.assertEqual(len(element.text), 0) Also ...
6 votes
Accepted

Make an if/then statement utilizing a non present element

You can either: Look for all element that match certain search criteria: if driver.find_elements_by_css_selector(my_locator): # No element found here Catch an exception when searching for a ...
  • 10.2k
6 votes
Accepted

Trying to login to Gmail with Selenium but "This browser or app may not be secure"

This Google Support page states that sign in via browsers that "Use automation testing frameworks" is being disabled for the following security reasons and Google advices to do "Sign in with Google" ...
  • 186
6 votes
Accepted

How do I enable ChromeDriver to use browser cache or local storage with selenium python

Yes, you are right, from Chrome capabilities documentations Use custom profile (also called user data directory) By default, ChromeDriver will create a new temporary profile for each session. ...
  • 186
5 votes
Accepted

Getting correct locator for an angular page element

The reason the first two don't work is because you didn't include the full class value for either the form or div element in your xpath. Try //form[@class='ng-untouched ng-pristine ng-valid']/div[2]/...
5 votes
Accepted

Try Assert Exceptions not failing test in python unittest or better way to loop through failures

I think you just need to re-raise the assertion error after printing out log messages: try: self.assertEqual(len(self.verificationErrors), 0) # no errors except AssertionError as e: for ...
  • 11.4k
5 votes
Accepted

How do you set up selenium tests to run nightly, and where do you store the files?

Where is the best place to store a large number of Selenium tests? The ideal place for your selenium tests would be a source code repository, like git or mercurial. You don't have to host the ...
  • 11.4k
4 votes

Page Object Design: Is there a Python equivalent to Ruby gems "site_prism" or "page_object"?

Another option is the page-objects library.
4 votes
Accepted

Python selenium - how can I loop a function to make 100 Copy accounts using different emails

If you're trying to register 100 accounts, this is a simple addition to your code to do that. for i in range(100): email_address = "money" + str(i) + "@qa.test" firstName.send_keys("mike") ...
4 votes

CSS Selector using ':contains' fails with `invalid element state: Failed to execute 'querySelector' on 'Document: is not a valid selector'`

CSS: The CSS2 contains function is not in CSS3; however, Selenium supports the superset of CSS1, 2, and 3. contains() is not part of the current CSS3 specification so it will not work on all ...
4 votes

Detecting tests that will never fail

Another idea which we have not yet applied in practice is Mutation Testing. Mutation testing (or Mutation analysis or Program mutation) is used to design new software tests and evaluate the ...
  • 11.4k
4 votes
Accepted

How to get start with selenium with python automation

The good news is that, even though you are switching languages, you are going to work with the same Selenium API, which is reflected in many languages. Things are gonna go easy since the API itself is ...
  • 11.4k
4 votes

How do you set up selenium tests to run nightly, and where do you store the files?

Where is the best place to store a large number of Selenium tests? In the project which they are testing. Always version control tests with the production code, or you will have a lot of extra pain ...
  • 468
4 votes
Accepted

What to test when "testing" a PDF download?

As I understand this, you have an application that takes some set of data per user, renders it to PDF, and allows the user to download the generated PDF file. If there are any errors, the PDF is not ...
  • 31.2k
4 votes
Accepted

Getting warning from unit test

Summing up what we had debugged and figured out: the problem comes from the static_file() function in the bottle library if we look at the source code of that static_file() function, we can find this ...
  • 11.4k

Only top scored, non community-wiki answers of a minimum length are eligible