36

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


33

Here's a solution. Set Firefox's preferences to save automatically, and not have the downloads window popup. Then you just grab the file, and it'll download. So, something like this: FirefoxProfile fxProfile = new FirefoxProfile(); fxProfile.setPreference("browser.download.folderList",2); fxProfile.setPreference("browser.download.manager.showWhenStarting"...


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.


14

I suspect this is not a TestNG issue. I would start by trying to produce a minimal set of tests that, when run together, cause failures. After that, I would explore these possibilities: Inter-test interaction changes test-application interaction: It is possible that interaction between your tests changes how your test interactions with your application. ...


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


13

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.


12

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

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

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


11

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


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


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

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


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

My personal experience is with testing iOS devices so I can only refer to those. Your question is broken up into three separate parts so I will answer each of those in turn. I'm thinking along the lines of a Firebug for the iPhone/iPad/Android/BB that can truly give more insight on the markup/scripts. This is supported in iOS6 by enabling the "...


9

Here is a script which loads jQuery through WebDriver. I've been using it successfully for quite some time. Features: -- will not overwrite any existing jQuery instance. -- will not alter the DOM under test or pollute the global namespace -- cleans up after itself to avoid memory leaks -- waits for jQuery to be fully loaded before returning. -- takes an ...


9

In the Selenium Simplified course the secret to the selector is really the 'value' not the 'type' as the 'value' identifies the WebElement uniquely on that page, coupled with a type 'just in case' WebElement checkBox1; WebElement checkBox3; checkBox1 = driver.findElement(By.cssSelector("input[value='cb1']")); checkBox3 = driver.findElement(By.cssSelector("...


9

This might be useful. driver.findElement(By.tagName("body")).sendKeys("Keys.ESCAPE"); OR JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("return window.stop");


9

These days, I'd say Selenium RC is not worth learning unless you have a specific need for it--for example, to work with legacy test code that uses it. I don't think it will give you a significantly better appreciation of the Selenium architecture. You can get that by exploring the Selenium code base if you have an interest. If you the know WebDriver API ...


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


9

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


9

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


8

Apache JMeter is really cheap, and by really cheap, I mean free. It should be able to handle the find operations you are looking for. The download link is: http://jmeter.apache.org/download_jmeter.cgi


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