Hot answers tagged

70

I think using selenium.webdriver.support.ui.Select is the cleanest way: from selenium import webdriver from selenium.webdriver.support.ui import Select b = webdriver.Firefox() # navigate to the page select = Select(b.find_element_by_id(....)) print select.options print [o.text for o in select.options] # these are string-s select.select_by_visible_text(.......


21

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.quit() – It basically calls driver.dispose method which in turn closes all the browser windows and ends the WebDriver session gracefully. You should use ...


20

You're actually creating a second Selenium session in your tearDown() function. You need to put the session created in setUp() into an instance variable, then close that session in tearDown(). class TestFoo(unittest.TestCase): def setUp(self): self.selenium = selenium('localhost', 4444, "*chrome", 'http://blackpearl/') self.selenium....


17

All the learning starts from step1. You have learned based on your own interest. I had a lot of support from this community and stackoverflow when I started writing automated tools. I can share my experience. 5 Rules for beginners getting into test automation: Rule#1 - Do not worry about design, error handling when you start writing your automation suite. ...


12

I wrote a javascript snippet as follows after reading replies from the webdriver google group: wd.execute_script("document.getElementById('allImages').value = '../uploads/b31f8a31-9d4e-49a6-b613-fb902de6a823.jpg';") Or as Sam suggested in the comment: image = wd.find_element_by_id("allImages") wd.execute_script("arguments[0].value = 'foo.jpg';", image) ...


11

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 based on #34 at code.google, the following code should work as well: public void login(String username, String password){ WebDriver driver = getDriver(); ...


10

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 selenium import webdriver options = webdriver.ChromeOptions() options.add_argument('lang=en') # options.add_argument('--lang=en') <- Tried this option as well ...


9

I have worked with Web Driver in both java and C# and I use In Java : WebDriver driver; driver.quit(); In C# : IWebDriver Driver; Driver.Quit();


8

Similar to Will's answer, but finds the <select> by its element name, and clicks based on the <option> text. from selenium import webdriver b = webdriver.Firefox() b.find_element_by_xpath("//select[@name='element_name']/option[text()='option_text']").click()


8

checkboxes = self.browser.find_elements_by_xpath("//input[@name='arr[]']") for checkbox in checkboxes: if not checkbox.isSelected(): checkbox.click() (Previous answer): I am not yet familiar with the python syntax, but this is what you can do: Return all elements with the given xpath: self.browser.find_elements_by_xpath("//input[@name='arr[]']...


8

I'm going with my favorite response here: it depends. Sometimes the decision is made because that's the language the tool supports. Sometimes the language is a flavor of the language used by the development team - this often happens where there's an expectation that the development team will be writing at least some of the test automation code. Sometimes ...


8

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 installed: $ brew update $ brew install pyenv Then we install all the needed python versions with pyenv. This might take time. See python.org/downloads for ...


7

My experience with automation is that it's invaluable for regression, particularly the kinds of regression that are tedious and painstaking to perform. A login script is usually a utility that happens as part of a larger script suite - which must, as Siva said, be object-oriented and data-driven if you don't want to create yourself a maintenance nightmare. ...


7

I found another solution. For me this worked like a charm and it's the prettiest way. driver.getSessionStorage().clear(); driver.getLocalStorage().clear();


7

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 WebDriver tests in Python. FitNesse is for end-to-end testing (browser automation) and Selenium/WebDriver in much superior replacement, especially if you ...


6

I haven't used the Python bindings, but as far as I know they should be equivalent to the Java ones. If I were you I would try to find the Python equivalents of findElements() and isDisplayed() that are available in the Java bindings. For example, I would do something similar to this: // ... myElementList = driver.findElements(By.Id("fancybox-close")) if ...


6

You may need to use .get_attribute("value"). instead of .text.


6

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 prefer Python over Java, because of one reason : Its simplicity. Our test team comprises of people who have little programming experience. However, most of ...


6

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 consider using Nose2, py.test, or just plain unittest/unittest2. Even though unittest from the Python standard library is a very mature test framework with built-...


6

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 to use open-source debugged version of such utility instead of reinventing the wheel. BTW I got the answer by googling "check broken links python" :-)


6

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 check this question for other options: https://stackoverflow.com/questions/9573244/how-to-check-if-the-string-is-empty


5

As it happens, that isn't (as far as I can tell) the official documentation, which is here: http://selenium.googlecode.com/svn/trunk/docs/api/py/index.html (Link is dead) Official documentation is here : https://seleniumhq.github.io/selenium/docs/api/py/api.html (And which does have the full API reference.)


5

You need to install the selenium bindings for Python. Try this: sudo pip install selenium


5

There are times when using the Page Object Pattern makes a lot of sense and times where it doesn't make as much sense. If you have a web application where it is basically one single dynamic page then it makes less sense, however you can still use "page" objects that are really more like "section" objects for common pieces, for example if you have a Left Nav,...


5

Do you need Selenium for this task? If you have an existing suite of Selenium tests, you can run them against the new site to verify the functionality is working, but in general Selenium is not the best tool for validating look and feel, or massive amounts of content. There are several link checker tools that will crawl all of the links and download all ...


5

Since you are looking into Selenium (as a test framework) start with Java, because Googling on "Selenium/Webdriver issue description" will often result in Java examples that you can re-use. There is just more people doing Selenium with Java then Python. Also Selenium it-self is mainly written in Java. For a project I would learn the language the application ...


5

As @Niels van Reijmersdal mentioned, it makes sense to use the language in which you have local experts available. But you don't have to use the same language - use the language in which your team will be more productive. Python and Ruby are almost identical in expression power. I would argue that Python is more readable, which is significant advantage when ...


5

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]/div/label OR //form[contains(@class,'ng-untouched')]/div[2]/div/label Note the use of contains() to match against a partial value. I've found this to be ...


5

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 message in self.verificationErrors: print(str(message)) raise # < HERE Also, if you want to check for severe console messages after every single ...


5

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 repository yourself and can use third-party services, code hosting solutions like github or bitbucket. And are there any tools which I can use to manage these ...


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