We changed our privacy policy. Read more.
37

Using the Select Utility Class The big secret to working with dropdowns is that you don't want to work with them as WebElements, but instead create a Select element for them. The Select class (java and python documentation) includes utility methods that allow you to perform common tasks. We will be working with the following html: <select id="...


23

For hacking WebDriver without real production purpose, you need to find some task that really motivates you. Don’t forget, WebDriver – is not only about test automation, people use the tool (not so widely) for many different purposes: crawling some data from websites, semi-automating real job-related tasks. For instance, a girlfriend of friend of mine ...


16

It is quite easy to hide the browser without XVFB. Just install PhantomJS. Then, change this line: driver = webdriver.Firefox() to: driver = webdriver.PhantomJS() The rest of your code won't need to be changed and no browser will open. For debugging purposes, use driver.save_screenshot('screen.png') at different steps of your code.


16

No, Selenium 2 / WebDriver is for web applications only. But there are other tools to automate desktop application GUI tests. http://en.wikipedia.org/wiki/List_of_GUI_testing_tools You can also search for "desktop application" on this site to find recommended tools.


14

PageObjects The code of automated test cases should be easy to understand and not too complex. If a test fails, we want to know why and this as soon as possible. To allow this exists PageObjects. PageObjects are classes that contains WebElements and every actions associated with those. A PageObject looks like this: class HomePage { WebDriver driver; ...


14

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


13

Thanks for your responses. But this is the script I'm using to resolve this issue public void waitUntilCountChanges() { WebDriverWait wait = new WebDriverWait(getDriver(), 5); wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driver) { int elementCount = driver.findElement(By.xpath(&...


12

You should never run automated tests against a website for which you don't have permission. The site owner could consider it a denial of service attack or an attempt at hacking. In theory, they could sue you or ask your ISP to drop you. If you do this using a company computer, you could put your company in jeopardy. Don't do it. Here are three sites ...


12

It looks like this issue has been logged as a bug for Selenium but has not yet been fixed: Issue 402: webdriver hangs on page load and does not give control back for script execution They are looking for a specific repro, maybe you could help them out by posting your specific repro? One person reported that removing any driver timeout options from their ...


12

Short answer: Yes it is a bad practise, unless you have a very very very good reason, do not use implicit wait. This Stack Overflow answers really puts the difference in great detail. (read this!) I once had someone on my team who thought it was a good idea, until I started researching why all our tests had such a long starting time. Somewhere in our setup ...


12

Do you think that time is the problem here? If so try to increase the time you are providing in Thread.sleep(); and see it that works out for you. If its not the time, then did you try to find out what the problem is? Are you getting any error?


11

This is how I would debug a Selenium session to find out what is happening: Step-by-step debugging: Most IDE's allow you todo step-by-step debugging, you could set a break point just before the point you want to investigate. This will pause the execution of the test and lets you examine the browser with its own tools. You can step thru each line of code one ...


11

The browser date/time functions are all JavaScript. You should be able to use Sinon.JS or TimeShift.JS to mock the date/time. Inject/Add the mocking framework during tests runs Mock the Date object with the JavaScript Executor Set the timezone Run tests Now all calls to the internal Date object will return the shifted time. For examples see this post with ...


11

Check below are the various methods to scroll your web page up & down: Scroll Down: import org.openqa.selenium.JavascriptExecutor; WebDriver driver = new FirefoxDriver(); JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("scroll(0, 250)"); //y value '250' can be altered Scroll up: JavascriptExecutor jse = (JavascriptExecutor)...


10

There are a number of tools available for testing mobile apps: a) Robotium b) Uiautomator c) Espresso d) Appium e) Calabash But my experience -I can suggest you Appium is the best tool for both Android & iOS mobile testing. I'm working on Appium from last 6 months in my organization it is pretty good. The main advantages of using Appium is- Cross-...


10

Look at the Wait commands rather than sleep - a search on this site or Google will give you lots of examples


10

Please use below code. driver.get("http://www.flipkart.com/"); driver.manage().window().maximize(); driver.findElement(By.linkText("Trimmer")).click(); WebElement scroll = driver.findElement(By.id("brand")); scroll.sendKeys(Keys.PAGE_DOWN);


10

No. Do not just split your pageObject into pageObject2, 3, 4, etc. This goes for all programming - split your classes logically by function, not arbitrarily! Your page object should be the source of truth for that specific page. When you start trying to interact with your page, does it really make sense that you should search between MyForm.java and MyForm2....


9

Strictly speaking you don't need to know how databases work to work with any automation tool. But without an understanding of databases and the ability to query them, you block off a large source of extra information you can use for validation. Some examples: Your application takes a person's name and contact details and stores them in three tables (for ...


9

Take the screenshot in the @After test tear down method, which is run after every test. This way you will always get a screenshot for both passed and failed tests. public class TestSample { static WebDriver driver; @Before public void setUp() { //start new webdriver session, for eg using firefox driver = new FirefoxDriver(); ...


9

The reason you are getting so many different matched is because you print it as you go through the loop. My personal suggestion, I like the KISS method, change the code to something like the following: public class Ex1 { private WebDriver d; @Test public void testUntitled() throws Exception { d = new FirefoxDriver(); d.get("http://register.rediff....


8

You can use WebDriverWait to synch with page load. Something like the following might help WebDriverWait wait = new WebDriverWait(driver, 15); //you can play with the time integer to wait for longer than 15 seconds.` wait.until(ExpectedConditions.titleContains("title")); //if you want to wait for a particular title to show up OR wait.until(...


8

'Welcome to the Internet' provides a ton of good real world examples that you can use to write some test automation code against. http://the-internet.herokuapp.com/


8

For testing it, your doing an extremely basic test. A major advantage of automation is that you can do a lot more testing. I would set up a datasource for names, declare them valid or invalid, and have it attempt to use it. I would also have it only use one of the special characters at a time and the rest be valid (As of now your essentially testing if any ...


8

Selenium is a tool that remote-controls a browser. You can use it to simulate a user interacting with a web site. JUnit is a framework for writing Java unit tests. It takes some of the grunt work out of organizing tests and generating reports. You can express each test as a method on a class; typically, you have multiple tests per class. JUnit will run ...


8

You can try setting implicit wait time. (Documentation) // 5 seconds implicit wait (C# code) IWebDriver driver = new FirefoxDriver(); driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));


8

Java My experience is, that the basics of Java suffice to start developing test cases with Selenium 2 / WebDriver. Myself started developing of Selenium test cases with a basic knowledge about Java. The more test cases I wrote and solutions I had to find, the more I leaned about the programming language. Unit Testing Framework (JUnit, TestNG) Write some ...


8

Without the Select class Everything I listed in my other answer can, of course, be done with judicious use of selectors. Since the Select class doesn't exist in Ruby (to the best of my knowledge), this is the only way to work with Select options in Ruby. Again, the HTML: <select id="mySelectID"> <option value="Value">Option</option> ...


8

List<WebElement> cheeses = driver.findElements(By.className("cheese")); findElements() does not wait, but returns list of elements (located by locator). List is empty if nothing is found (reference). Also, Selenium elders very strongly advise to use only explicit waits (no implicit). And especially warn about mixing implicit and explicit waits. In ...


7

You used to be able to use PhantomJS for this, but since PhantomJS itself is discontinued, so is the Selenium PhantomJS driver. The good news is, that you can simply use Chrome. Chrome itself has gotten the feature of being able to run without an actual browser window. So after instantiating your chrome driver, you can simply add instructions to work ...


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