Selenium Webdriver Error Unknown strategy class - selenium

I've been trying to use Selenium to test my application. I wrote the initial tests using the Selenium IDE but, when I converted the IDE tests to Selenium Webdriver tests I got errors for about half of my code! So I'm going through each of the errors trying to get the code to work.
The error I'm getting in Web Driver is
ERROR: Caught exception [Error: unknown strategy [class] for locator [class=x-tool-close]]
In Selenium IDE it had simply been Command Click and target class=x-tool-close.
Thanks,

It has been awhile since I posted this question so I cannot be sure if I am addressing what the problem was exactly, but with that said the following is what I use for the command I mentioned above.
driver.findElement(By.xpath("//img[contains(#class,'x-tool-close')]")).click();
The structure of this command is very basic. Since the id of my elements are dynamic I search by xpath. Inside the quotation marks we have said xpath. We are searching for an 'img' element whose class attribute contains 'x-tool-close'. Then we are executing the selenium webdriver command click upon that element.

Related

nightwatch test fails with multiple click events in sequence

When running a nightwatch.js test on a browser with a checkbox that
is not visible using the following code.
browser.moveToElement('input[id="2verificationYes"]')
.click('input[id="2verificationYes"]')
I get the following error :
An error occurred while running .click() command on ,input[id="2verificationYes"]>: unknown error: Element `element` is not clickable at point (111, 701). Other element would receive the click: `otherElement`
at process._tickCallback (internal/process/next_tick.js:64:7)
I am using
nightwatch v.1.0.19, chromedriver ^2.43.0, geckodriver ^1.16.2, selenium-server ^3.14.0
I have tried using the callback functions with each call but the result is the same. Tried to research how to scroll to an element in nightwatch, but the api's don't have that. It is my understanding the the moveToElement function is supposed to scroll to the element.
For me moveToElement is working good. I believe you are seeing error because you forgot to mentioned the Xoffset and Yoffset.
Try my below work around and let me know:
browser.moveToElement('input[id="2verificationYes"]',Xoffset,Yoffset)
.click('input[id="2verificationYes"]')
for your reference: search 'moveToElement' here
Can you try giving '0' and let me know:
browser.moveToElement('input[id="2verificationYes"]',0,0)
.click('input[id="2verificationYes"]')
Same time try giving little wait time to narrow down the issue. Good luck

how to locate element with selenium webdriver

After exporting a test in Visual Studio using Selenium webdriver, I execute the test case in VS and it fails when trying to locate an element in the test. The element is a tab within a page but the test case cannot find the id of the tab. This is the failing line driver.FindElement(By.Id("ui-id-14")).Click(); and I also tried to locate the element with the ClassName driver.FindElement(By.ClassName("ui-tabs-anchor")).Click(); by inspecting the element in Chrome browser but it still fails. Anyone can tell me what am I doing wrong here? Thank you in advance.
driver.FindElement(By.Id("ui-id-14")).Click();
driver.FindElement(By.ClassName("ui-tabs-anchor")).Click();
How Do you initalize you driver? A common mistake is not having a implicit wait with selenium. The driver tries to locate the element as soon as the document is ready, which is not feasible with "normal" JS applications as they are rendered after the document is ready. Try:
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
This way the driver will try to find the element every 0.5 seconds up to 30 seconds before throwing an Exception. By the way: Welcome to stackoverflow. Please consider posting your code/code snippets, that makes analysis often easier. My suggestion is purely made from my experience with people being new to Selenium.

JavaScript Error: e is null popup during Selenium Test

I have test which is resulting in a Firefox pop-up which looks like this:
The exception is an InvalidOperationException and it goes on to say
JavaScript Error: "e is null" then making reference to a JavaScript file called commandprocessor.js
I am using the 2.44.0 version of WebDriver with Firefox version 33.
Out of completeness, I will also add that this pop-up is not throw on if a user manually follows the steps in that test.
Any ideas what is going on? Previous SO questions with similar error have yielded no answer.
Could be an issue with the driver itself. Have you looked at these issues logged with selenium webdriver?
Issue 7977: Upredictable javascript errors "e is null"
Issue 8095: fxdriver.error.toJSON fails to match qualified method names containing $
Based on the rev logs these fixes seemed to have been added after 2.44.0 release so they may not have made it yet to a release version.
In one of the callbacks, the code included
$('#confirmRegistration').attr('href', 'javascript:location.reload();');
Seems to be forcing a page reload, which the WebDriver did not like.

issues in running selenium in internet explorer

Hi I am trying to run my selenium webdriver on IE9.
WebDriver version : 2.32.0
IE:9
IEDriverServer_win32:2.32.3
windows7
Below is my code:
File IEDriver=new File(System.getProperty("user.dir")+File.separator+"BrowserDrivers"+File.separator+"IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", IEDriver.getAbsolutePath());
DesiredCapabilities cap=DesiredCapabilities.internetExplorer();
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver=new InternetExplorerDriver(cap);
driver.get("http://in00616:8421/GS");
Thread.sleep(3000);
//driver.findElement(By.id("j_username")).sendKeys("admin");
//driver.findElement(By.id("j_password")).sendKeys("admin");
driver.findElement(By.xpath(".//input[#id='j_username']")).sendKeys("admin");
driver.findElement(By.xpath(".//input[#id='j_password']")).sendKeys("admin");
driver.findElement(By.id("login")).submit();
Thread.sleep(2000);
driver.findElement(By.xpath(".//button[text()='Securities']")).click();
Thread.sleep(2000);
driver.findElement(By.xpath(".//span[text()='Issue']")).click();
Thread.sleep(2000);
driver.findElement(By.id("tabSecurities_Issue_Request_for_Issues")).click();
Above code logs in to my site but then when I try to click on Securities button I am not able to do it. Securities button starts flickering and then I am notified that unable to find the element.
Exception in thread "main" org.openqa.selenium.NoSuchElementException:
Unable to find element with xpath == .//span[text()='Issue Type']
(WARNING: The server did not provide any stacktrace information) –
Same code works fine in FireFox.
Please help as i am suppose to test my UI on InternetExplorer.
I think it is the version compatibility issue.
Can anyone suggest the compatible version set for IEDriverServer, Selenium WebDriver and IE which is in working condition.
As this SO answer points out, IE does not have native XPath support. Instead, Selenium WebDriver uses an old third party xpath library when IE is being used. Firefox has integrated support for XPath, which is why your selectors work fine in that browser.
I would highly recommend you update your selectors to instead use CSS selectors. They are supported across all browser, are easier to read, understand, and pick up, and they are pretty fast.
You can learn more about how to use CSS selectors from some different tuturials here, here, and here, and a CSS selectors cheatsheet.
Also, whenever possible, please try to not select an element by the text it contains. If you can select an element by its ID, class, other attribute, or even through the DOM chain (i.e. "div.1 > div.2 > span.a > a.b"), is better than trying to select an element by text.
Webdriver has difficulty with IE using locators. It seems like Murnal has difficulty using CSS locator. My advice would be you HAVE to use other locators if one doesnt work. This issue comes again and again while using non firefox browser. In the meantime an easier way to come up with alternate locator is use Firefox selenium IDE, there in the boxes where you type command you will see it gives alternate locator as well. Copy that and try plugging tha in your webdriver's findelement script.
Hi all i have found out that it was the issue of Selenium Webdriver 2.32 with IEDriver_Server2_32. After trying out permutation & Combination with latest available webdriver versions and IEDriver_Server, i have found out suitable stable configuration to work on IE9 below is the stable configuration : Webdriver : 2.33.0 IEDriver_Server : 2.33.0. There is still small issue but i am trying to look for workaround. Issue : In IE if some control's tooltip overlaps other control than IE is not able to find out that control. i guess this issue is with IEs working. IE uses nativeEvents to perform operation hence it is not able to locate that control. In FF it is able to find out that control and it is working fine. Thanks everyone.

Selenium RC cant find locator

I have the following locator:
css=tr:contains('First page') + tr table td:contains('Yes') input
I can find it on the page using Selenium IDE, but my Selenium RC test fails trying to find it.
What can be the matter?
Try Using Fire bug to locate the element and then using the same try running the code in
selenium RC.
Many times the selenium IDE reads the location in Short due to which it fails try the above method.