34

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


31

By.xpath("//button[contains(.,'Add Strategy')]") By.xpath("//button[contains(.,'Submit')]") Notice that it is same as: By.xpath("//button[contains(text(),'Add Strategy')]") By.xpath("//button[contains(text(),'Submit')]")


29

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


26

First of all why do you want to download the file? Are you going to do anything with it? The majority of people who want to download files just do it so that they can show an automation framework downloading files because it makes somebody non-technical ooo and ahh. You can check the header response to check that you get a 200 OK (or maybe a redirect, ...


22

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


19

As far as I know there is no easy way to make Selenium download files because browsers use native dialogs for it which cannot be controlled by JavaScript, so you need some "hack". Check this, hope it helps.


18

The default WebDriver setting for timeouts is never. WebDriver will sit there forever waiting for the page to load. The following timeouts are available: /** * An interface for managing timeout behavior for WebDriver instances. */ interface Timeouts { /** * Specifies the amount of time the driver should wait when searching for an ...


16

This is possible with Selenium 2 and WebDriver. I'm not sure if it is with different versions. In Selenium 2 with WebDriver you can call webDriver = new FirefoxDriver() which spawns a browser, and that browser will stay open for the duration of your testing, or you can choose to close it with webDriver.Quit(). I like to close my browser window between tests ...


14

I find the Page Object pattern very useful, and use a modified PageFactory (parameterized for custom timeouts). I also use WidgetObjects (basically, PageObjects with a parent reference via constructor) to represent common themes across pages. I don't think URL association is necessary on all pages, so I keep it out of my base class. URL params? I keep my ...


14

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


13

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


12

One option is HTMLUnit, which is headless but has its own proprietary JavaScript rendering engine, so it is possible that it will behave differently than existing browsers (If you do use HTMLUnit, don't forget to enable JavaScript when you instantiate it). The second option is to use XVFB; this will run the tests in a virtual frame buffer environemt. This ...


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

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


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

If you can, try & promote the idea of test first development (aka TDD, BDD, ATDD, Specification By Example) with Continuous Integration (frequent commits to a pipeline such as Hudson or GO from Thoughtworks which continuously runs the automated checks to see if any of them have broken after a recent commit) Before Developers write the code, they write ...


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

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


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

A possibly more generic solution to this problem is to wait for the jquery to complete. You can do this with a function like this: public void WaitForAjax() { while (true) // Handle timeout somewhere { var ajaxIsComplete = (bool)(driver as IJavaScriptExecutor).ExecuteScript("return jQuery.active == 0"); if (ajaxIsComplete) ...


9

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


9

It is not necessary to create a new instance of the driver object. You can use JavaScript to open a new window which is a lot faster. To open the window: IJavaScriptExecutor jscript = driver as IJavaScriptExecutor; jscript.ExecuteScript("window.open()"); Then to switch windows, use the window handles: List<string> handles = driver.WindowHandles....


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

I had the same problem and actually dislike this "feature" in Selenium. In my C# abstraction layer I replaced getText with this: return ((IJavaScriptExecutor)webDriverInstance).ExecuteScript("return arguments[0].innerHTML", elementInstance).ToString();


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


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