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....
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 ...
12
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 ...
8
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 ...
8
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
...
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 ...
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 ...
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....
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 ...
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" ...
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.
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
4
votes
ElementNotVisibleException: Message: element not visible
1.Use following XPath Locators:
//button[contains(@id,'shippingSubmit') and (@name,'shipSubmit')];
OR
//button[contains(@id,'shippingSubmit') and starts-with(@class,'visible-xs-block')];
OR
//...
4
votes
How to run Robotframework test cases in a particular order from different suites?
Unfortunately, the best workaround for this is to use prefixes with underscores, as it is mentioned in the User Guide.
For example:
01__my_suite.html -> First test case/suite to be executed.
...
4
votes
Accepted
Is there a way to check the font style , colour , size etc using selenium python
element.value_of_css_property(property name (string)) will return value of the specified property, e.g. element.value_of_css_property("font-size") returns the CSS "font-size" value.
Here are the ...
4
votes
Accepted
How correct I executed the test case?
You would normally use an assert statement.
So
assert condition, "Custom message on failure of assert"
I'm not 100% on python but think the formatting would be:
assert error.is_displayed(),"Error - ...
4
votes
Struggling with Selenium in python 'is not clickable at point (x, y)' exceptions during testing
From the question, it could be inferred that you are not concerned about the visibility of the grey element. Sometimes in angular based websites isenabled isdisplayed etc won't work properly due to ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
python × 547selenium-webdriver × 445
automated-testing × 146
chromedriver × 29
selenium2 × 28
robotframework × 27
browser-automation × 26
xpath × 22
java × 19
appium × 18
unit-tests × 18
test-automation-framework × 14
pytest × 13
mobile-automation × 11
test-strategy × 11
behave × 11
chrome × 10
selenium3 × 9
ios × 8
test-design × 6
javascript × 6
mac × 6
uiautomation × 5
firefoxdriver × 5
mock × 5