I am doing an automation with Selenium Webdriver using Java. I need to click the class name inside the span tag.
Example
For this i used xpath to select class="selcteME" and used click(). This works fine if I put break point in debug mode but when I run the script without break point in debug mode object is not selected.
Please share if you have solution or suggest me how can I get the class name inside the span tag
() without xpath
Have you tried by CSS Selector?
I suggest use some IDE to generate basic test and then use your logic.
Related
The website which for which I am trying to do automation is a secure website where some functions like right clicking have been disabled. I am using the exact xpath for the login input field but it is not working. My Xpath is as follows:
driver.findElement(By.xpath("//input[contains(#class,'input')]")).sendKeys("Aa12");
SeeTest provides a way for opening the developer tools even in such cases.
They also have different versions of chrome in which you can try your scenario.
Their documentation might help you more on this.
I am working on a application with nested iframes and I want to validate content of active iframe.
How to take screenshot of that active iframe?
Assuming Java is your programming language for the test,
first use switchTo() method to focus on wanted iframe:
driver.switchTo().frame(driver.findElement(By.id("frameId")))
Now regarding snapshot of the iframe, I would use ashot open source library which could help you take a snapshot of particular element. In your case, it would be the element which located in the highest level inside the iframe.
Is it possible to capture user input/actions with Selenium WebDriver, in the same way that you can use the Selenium IDE for recording / creating tests?
i.e. when the user enters a URL, clicks a link, fills in a text box, clicks a button etc etc.
I'd like to be able to capture these actions using the WebDriver rather than just using the Selenium IDE, as I want to integrate with other classes available in my Java application.
I attempted to offer a viable solution in Record Actions using Selenium
Hope this helps.
You can't 'record' a set of actions with Selenium WebDriver, you will need to write those steps manually.
Strictly speaking you can capture user input by using the WebDriver API in your chosen language (C#, Java, PHP, Ruby. Python, Perl or JavaScript) and it vaguely resembles using the DOM. If it suits your requirements you could use configuration files to supply some of your user input.
Navigate to a URL:
WebDriver driver = new FirefoxDriver();
driver.get('url')
Click a link/button:
WebElement element = driver.findElement(By.id("coolestWidgetEvah"));
element.click();
Enter Text in a field:
WebElement element = driver.findElement(By.id("coolestWidgetEvah"));
element.sendKeys('userinput');
For more information on the API Selenium HQ is pretty definitive:
http://seleniumhq.org/docs/03_webdriver.html#introducing-the-selenium-webdriver-api-by-example
If you're going from Selenium IDE to writing tests it'd be really useful to check out the page object pattern as I've found it makes your tests more maintainable in the long-run. This link is a good starting point because it gives an overview, and a visual representation of what you get by following the pattern:
http://blog.josephwilk.net/cucumber/page-object-pattern.html
Hope that helps.
As far as I'm aware, there isn't an easy way to do it - but recording on IDE and exporting as a java file has worked well for me (File -> Export test case as...). I usually do it to c# but have used it with java.
I'm using Selenium to navigate a webpage which has a link called "Mail", using WebDriver (just recently switched from RC to WebDriver). I want to click on the link but the testcase always fails with the error:
org.openqa.selenium.NoSuchElementException: Unable to locate element:
{"method":"link text","selector":"Mail"}
When inspecting the element with Firebug I get the following HTML:
Mail
This is the Java which attempts to click the link:
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.linkText("Mail"));
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
I can see that the element is present on screen but still, the test case fails.
Does anyone know what I might be missing here or an alternative way to find the link element?
Try via XPath. Example:
driver.findElement(By.xPath("/a[text()='Mail']"));
Would also be worthwhile double checking to ensure there are no iframes on the page.
Even i had faced this situation once. View your source code and find out if the element you are looking for is inside a frame. If yes, first switch to the frame in which the element is located and then look out for the element. It worked this way for me.
So far the best workaround I found for cases like this:
Open Firefox with Selenium IDE installed
In firefox open the test page
Run selenium IDE, start recording and click the link
Selenium IDE will offer you ways how to locate the target. If you switch to relative XPath, it should do the magic (Or, in my cases, it always helped)
I am working in Selenium RC. Can anyone please let me know how to write xpath for button in Selenium (Java)?
You should develop the script in the Selenium IDE (download) before porting it to Selenium RC. In Selenium IDE, when you click anything on the webpage, it should automatically generate some kind of selector for the element you clicked. Then, once you've recorded all the events, you Format it in whatever language you're using, and then you copy and paste it to your Selenium RC code.
But the Recorder Javascript isn't foolproof (e.g. if you click on a div that causes some XMLHttpRequest or setTimeout, it won't be recorded). Or, the click may be recorded but you may not like the selector that Selenium chooses for the element. In either case, you'll have to write your own selector based on the DOM structure. To see the DOM structure, open Firebug if you're in Firefox (F12), or open the Inspector if you're on Chrome (Ctrl-Shift-J) Fortunately, Selenium understands a bunch of selector syntaxes, so you can use CSS selectors if you don't know XPath.
If you do decide to use XPath, you'll have to learn it first. I haven't found any good tutorials (and I'm not a fan of w3schools). But feel free to use a bookmarklet to test XPaths that I wrote. You'll probably end up with something like //button[.="text on button"], or //input[#value="text on button"].
You can find button Xpath by using Firebug which is an add-on for Firefox and as above answer Selenium IDE is also another, easier option to find.