Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Hot answers tagged

68

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(.......


40

The easiest way that I have found was to do something along the lines of: el = driver.find_element_by_id('id_of_select') for option in el.find_elements_by_tag_name('option'): if option.text == 'The Options I Am Looking For': option.click() # select() in earlier versions of webdriver break This may have some runtime issues if there are a ...


20

While it's not updated as regularly as it once was, Grig Gheorgiu's Python Testing Tools Taxonomy is considered by Pythonistas to be an excellent reference point for tools. It covers the following kinds of testing tools: Unit Testing Tools Mock Testing Tools Fuzz Testing Tools Web Testing Tools Acceptance/Business Logic Testing Tools GUI Testing Tools ...


16

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(); ...


9

Burp Suite would be worth checking out if you're fuzz testing web applications. As the name implies, it's actually a suite of different web security testing tools - I used it for the first time on Monday in a pen testing workshop and it seems like a tremendously useful tool. Burp Intruder is the tool used for fuzzing attacks - and here's a video tutorial ...


8

Yes, you're on the right path (though I have a caveat or two). More generally than "raise the right exception": The tactic is to make sure that no matter how SVN responds to your app's commands, your app responds as you wish. For me, the biggest challenges when mocking third-party code is to characterize: All the ways my code uses the third-party code All ...


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 ...


8

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 ...


7

The simplest option is to just mark the line as ignored by your coverage tests. You know more than coverage.py does, you can just excuse the line from the measurements: if __name__ == '__main__': # pragma: no cover return main(sys.argv) You can also use some tricks with coverage.py to get it to measure code in launched subprocesses. This sounds ...


7

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()


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

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 ...


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

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


6

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 ...


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" :-)


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

I had only one experience of automation testing for Qt apps on Linux. The tool I used is Squish, and it supports Java, Web and Mobile testing as well. The test scripts are written in python. Just FYI. It's a commercial product, you need to buy the license.


5

Remove the uncovered line from your .py file and use python -c "import foo; foo.main(args);" You can wrap that in an alias or a bash function.


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 ...


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