Why can Selenium not find XUL buttons? - java

I'm trying to use Selenium to test a Firefox add-on, but it doesn't find the "Preferences" button in about:addons:
extensionEntry.findElement(By.className("preferences")).click();
results in
org.openqa.selenium.NoSuchElementException: Unable to locate element: .preferences
Is this the wrong way to get a reference to the button? I've tried navigating the XUL in the Inspector, and there it definitely has the right class.

Selenium is not what you should be using to write test scripts for these type of applications.
As suggested by AutomatedTester, refer to his answer https://stackoverflow.com/a/5700516/3465845

Related

I am trying to access secure website where right button click is disabled. by using selenium Xpath cannot click on elements

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.

Selenium WebDriver does not find element by XPATH

I'm trying to write a Selenium Testcase and started with the Selenium IDE in Firefox.
The test is working quite fine there. Now I want to automate that test with Selenium Webdriver and exported the according JAVA class.
Everything is setup and working fine so far (the Internet Explorer window is opening, the according page is displayed).
BUT: Selenium Webdriver does not find the element.
I want to get the following element:
<div class="x-grid3-cell-inner x-grid3-col-instance/status" unselectable="on">Open</div>
and I have the following code:
WebElement openWorkItem = driver.findElement(By.xpath("//div[contains(text(),'Open')]"));
System.out.println(openWorkItem.getText());
In the testcase with Selenium IDE the statement is pretty much the same, and it is working:
<td>//div[contains(text(),'Open')]</td>
The only difference is, that the Selenium IDE is only available in Firefox, but in the end I want to have the test executed in IE with Selenium WebDriver.
Any help is very much appreciated.
==Update==
I executed driver.getPageSource() and now see that the HTML part I am looking for is not available because it seems to be located in an iFrame. Any ideas?
You can use findElement to get the frame webelement and have it used with the switchto() method.
driver.switchTo().frame(driver.findElement(By.xpath("iframe[contains(#name=pngNewC‌​ase1143241142570_IFrame)]")));
If you have some other attribute like src, you can try the below.
WebElement frame=driver.findElement(By.xpath("//iframe[#src='showNewClaimForm.action']");
driver.switchTo().frame(frame);

Selenium Webdriver in xpath object is not found

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.

WebDriver unable to locate element (link/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)

How to use Xpath of button in Selenium RC?

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.

Categories