softassert not being called.. Only getting NoSuchElementException - selenium

In one my testcase I am trying to find whether an element is displayed after login.
softAssert.assertTrue(landing1PageFuncs.getSetupBtn().isDisplayed(), "Login Failed");
softAssert.assertAll();
getSetupBtn getter method is as below
public WebElement getSetupBtn() {
return AppWait.waitForElement(driver, setupBtn , Constants.WAITTIME);
}
waitForElement function is as below
public static WebElement waitForElement(WebDriver driver, WebElement element, int timeOutInSeconds) {
try {
driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
element = wait.until(ExpectedConditions.visibilityOf(element));
driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_ELEMENT, TimeUnit.SECONDS); //reset implicitlyWait
} catch (Exception e) {
logger.warn(element + " not found even after waiting for: " + timeOutInSeconds + " seconds");
logger.warn(e, new RuntimeException());
}
return element;
}
But what I am observing is that isDisplayed method is never invoked. Hence the soft assertion is not being fired.
All I get is the exception as below:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//*[#id='page_content_inner']/div/a[1]/div"}
Command duration or timeout: 19 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'justdial', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-86-generic', java.version: '1.8.0_91'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=46.0.1, platform=LINUX, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 6b9e0607-ee41-42b8-bb58-0f7d6cc32481
*** Element info: {Using=xpath, value=//*[#id='page_content_inner']/div/a[1]/div}
at sun.reflect.GeneratedConstructorAccessor13.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:500)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355)
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.openqa.selenium.support.events.EventFiringWebDriver$2.invoke(EventFiringWebDriver.java:103)
at com.sun.proxy.$Proxy9.findElement(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver.findElement(EventFiringWebDriver.java:188)
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
at com.sun.proxy.$Proxy11.isDisplayed(Unknown Source)
at org.justdial.jdomni.functionaltests.LoginPageTests.chkLoginWithValidCred(LoginPageTests.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:74)
What I am doing wrong? I am looking for a solution which goes till the Assertion and says "Login Failed"
Any help appreciated.

Your element cannot be found, so isDisplayed() cannot be determined. isDisplayed() can only be called on an element that exists and has already been found, that is why your assertion is never called.
landing1PageFuncs.getSetupBtn() throws an exception before isDisplayed() is being called.
If you want to find out if an element exists on the page, you should use driver.findElements(By.xpath('locator')).size > 0 instead of driver.findElement(By.xpath('locator').isDisplayed()

Since the element is not available in DOM, u cannot apply a soft assertion and obviously u'll get NoSuchElementException.
you can write a utility method like below to verify the whether the locator exists or not in the DOM.
public class verifyloc {
public static void main(String a[]) {
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.co.in/");
String loc = "//input[#id='lst-ib']";
By locator = verifyElementPresent(driver, loc);
System.out.println("Locator is : " + locator);
}
public static By verifyElementPresent(WebDriver driver, String locator) {
try {
driver.findElement(By.xpath(locator));
return By.xpath(locator);
} catch (Throwable e) {
return null;
}
}
}

Related

Not able to click on link obtain using findElements method

this is just a simple code to obtain all links from a particular section of a web page; click on those links get the title and return back to the parent page and repeat process for next one. But after clicking on 2 links I am getting error "stale element reference: element is not attached to the page document" Please refer code and let me know what I am missing.
I am able to open links in a new tab and get the title of child pages. But I want to open a link in the same tab.
package test;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LinkTest {
public static void main (String[] args) throws InterruptedException{
System.setProperty("webdriver.chrome.driver", "C:\\ChromeDriver\\1\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.qaclickacademy.com/practice.php");
WebElement driverFooter = driver.findElement(By.xpath("//div[#id='gf-BIG']"));
WebElement footerC1 = driverFooter.findElement(By.xpath("//table/tbody/tr/td/ul[1]"));
List<WebElement> links = footerC1.findElements(By.tagName("a"));
for(int i=0;i<links.size();i++){
links.get(i).click();
System.out.println(driver.getTitle());
driver.navigate().back();
}
}
}
It should open all links and get the title and return to parent page for next iterator. Below is output and error,
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1550488224.725][WARNING]: Timed out connecting to Chrome, retrying...
Practice Page
REST API Tutorial
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
(Session info: chrome=72.0.3626.109)
(Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 6 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
System info: host: 'DS-SGH631RNL8', ip: '10.118.59.16', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{mobileEmulationEnabled=false, timeouts={implicit=0, pageLoad=300000, script=30000}, hasTouchScreen=false, platform=XP, acceptSslCerts=false, goog:chromeOptions={debuggerAddress=localhost:53075}, acceptInsecureCerts=false, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=ignore, applicationCacheEnabled=false, rotatable=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1), userDataDir=C:\Users\RUSHIK~1.KAD\AppData\Local\Temp\scoped_dir11700_2428}, takesHeapSnapshot=true, pageLoadStrategy=normal, strictFileInteractability=false, databaseEnabled=false, handlesAlerts=true, version=72.0.3626.109, browserConnectionEnabled=false, proxy={}, nativeEvents=true, locationContextEnabled=true, cssSelectorsEnabled=true}]
Session ID: e1a6bdd0b525d1c6e1d940a2ec156e51
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:85)
at test.LinkTest.main(LinkTest.java:23)
You are getting StaleElementReferenceException which comes when the element you are trying to access is no longer available in the dom or has become stale, to correct it you need to pick the elements again and then operate on it. You can modify your code like:
System.setProperty("webdriver.chrome.driver", "C:\\ChromeDriver\\1\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.qaclickacademy.com/practice.php");
WebElement driverFooter = driver.findElement(By.xpath("//div[#id='gf-BIG']"));
WebElement footerC1 = driverFooter.findElement(By.xpath("//table/tbody/tr/td/ul[1]"));
List<WebElement> links = footerC1.findElements(By.tagName("a"));
for(int i=0;i<links.size();i++){
driverFooter = driver.findElement(By.xpath("//div[#id='gf-BIG']"));
footerC1 = driverFooter.findElement(By.xpath("//table/tbody/tr/td/ul[1]"));
List<WebElement> newLinks = footerC1.findElements(By.tagName("a"));
newLinks.get(i).click();
System.out.println(driver.getTitle());
driver.navigate().back();
driver.navigate().refresh();
}

Getting java.lang.NullPointerException while finding a table with Selenium Webdriver

I am new to Selenium Webdriver. I am getting Null Pointer exception while trying to find the rows present in the table. Can anyone please help me to resolve this? Please find the below scenario and code that I am using for this.
URL: http://newtours.demoaut.com/
Scenario: To click on each link that present in the table present in the left hand side of the page. Just under Mercury Tours image.
Here is code that I am using,
public class HomePage {
private WebDriver driver = null;
public HomePage(WebDriver driver){
this.driver = driver;
}
public void VerifyTableLink() throws InterruptedException{
List<WebElement> rowObj = driver.findElements(By.xpath("//td[p[img[#alt='Mercury Tours']]]/table/tbody/tr"));
System.out.println("testttt");
for(int i=0;i<rowObj.size();i++){
WebElement we = driver.findElement(By.xpath("//td[p[img[#alt='Mercury Tours']]]/table/tbody/tr["+i+"]/td[2]/a"));
we.click();
Thread.sleep(5);
driver.navigate().back();
String text = we.getText();
System.out.println(text);
}
}
}
public class VerifyNavigationTable {
WebDriver driver = null;
#Parameters({"bname","appurl"})
#BeforeMethod
public void preCondition(#Optional("Chrome")String brow, #Optional("http://newtours.demoaut.com/")String url){
driver = BrowserSelection.getBrowser(brow);
BrowserSelection.openURL(url);
}
#Test
public void verifyTableLink() throws InterruptedException{
HomePage hp = new HomePage(driver);
hp.VerifyTableLink();
}
}
Exception Message:
[Utils] Directory D:\My Selenium Training\Practical\SeleniumLearning\SeleniumPractice4\test-output\Default suite exists: true
FAILED: verifyTableLink
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//td[p[img[#alt='Mercury Tours']]]/table/tbody/tr[0]/td[2]/a"}
(Session info: chrome=54.0.2840.99)
(Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT 6.2.9200 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 10.07 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'Bishnu', ip: '192.168.0.107', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf), userDataDir=C:\Users\Bishnu\AppData\Local\Temp\scoped_dir10480_1335}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=54.0.2840.99, platform=WIN8, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: c1401a5ed7966a2f15d6570c612b2449
*** Element info: {Using=xpath, value=//td[p[img[#alt='Mercury Tours']]]/table/tbody/tr[0]/td[2]/a}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:368)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:473)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360)
at in.prolearn.newtours.pages.HomePage.VerifyTableLink(HomePage.java:20)
at in.prolearn.newtours.testcases.VerifyNavigationTable.verifyTableLink(VerifyNavigationTable.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:646)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:811)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1137)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:753)
at org.testng.TestRunner.run(TestRunner.java:607)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:368)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:363)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:321)
at org.testng.SuiteRunner.run(SuiteRunner.java:270)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1284)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1209)
at org.testng.TestNG.runSuites(TestNG.java:1124)
at org.testng.TestNG.run(TestNG.java:1096)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================
Any suggestion will help me to understand the tool in better way.
Thanks
To find each row of the table you can use this xpath: //tr[#class='mouseOut']
Since you are interested only on links("a" nodes), I suggest to write your code like this:
List<WebElement> linksInTable = driver.findElements(By.xpath("//tr[#class='mouseOut']//a"));
for(WebElement a : linksInTable){
// write what you want to do with each link
}
You might also encounter a problem because you are using "back" in your codes. Probably(you should test it to become sure) you should find web elements again each time you back to the main page. Something similar to:
for(int i=0;i<linksInTable.size();i++) {
String text = linksInTable[i].getText();
System.out.println(text);
linksInTable[i].click();
driver.navigate().back();
linksInTable = driver.findElements(By.xpath("//tr[#class='mouseOut']//a"));
}

selenium webdriver in Internet Explorer throwing an error even after done all required setting

public class FirstTest { WebDriver driver; #Test public void test() { System.setProperty("webdriver.ie.driver","C:\\Users\\Priyanka\\Documents\\datadriver\\IEDriverServer.exe"); driver=new InternetExplorerDriver(); //driver=new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://gmail.com"); driver.findElement(By.id("userid")).sendKeys("Abc#gmail.coms"); driver.findElement(By.id("pwd")).sendKeys("abc#167"); driver.findElement(By.name("Submit")).click(); } }
This is my code.It will open the given URL but thows an error when trying to find webelement Error message:
FAILED: test org.openqa.selenium.NoSuchWindowException: Unable to find
element on closed window (WARNING: The server did not provide any
stacktrace information) Command duration or timeout: 28 milliseconds
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09
19:55:52' System info: host: 'Priyanka-PC', ip: '100.74.201.94',
os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1',
java.version: '1.7.0_79' *** Element info: {Using=id, value=userid}
Session ID: fc075a9b-5a50-42fa-ba96-ce2258254d4a Driver info:
org.openqa.selenium.ie.InternetExplorerDriver Capabilities
[{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0,
ignoreZoomSetting=false, enablePersistentHover=true,
ie.ensureCleanSession=false, browserName=internet explorer,
enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss,
version=-1, pageLoadStrategy=normal, ie.usePerProcessProxy=false,
cssSelectorsEnabled=true, ignoreProtectedModeSettings=false,
requireWindowFocus=false, initialBrowserUrl=http://localhost:22334/,
handlesAlerts=true, ie.forceCreateProcessApi=false, nativeEvents=true,
browserAttachTimeout=0, ie.browserCommandLineSwitches=,
takesScreenshot=true}] at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at
org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
at
org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:353)
at
org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:403)
at org.openqa.selenium.By$ById.findElement(By.java:218) at
org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:345)
at demo.FirstTest.test(FirstTest.java:20) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606) at
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:643) at
org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820) at
org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128) at
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at
org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782) at
org.testng.TestRunner.run(TestRunner.java:632) at
org.testng.SuiteRunner.runTest(SuiteRunner.java:366) at
org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361) at
org.testng.SuiteRunner.privateRun(SuiteRunner.java:319) at
org.testng.SuiteRunner.run(SuiteRunner.java:268) at
org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at
org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at
org.testng.TestNG.runSuitesSequentially(TestNG.java:1246) at
org.testng.TestNG.runSuitesLocally(TestNG.java:1171) at
org.testng.TestNG.run(TestNG.java:1066) at
org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113) at
org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206) at
org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)
I have done below settings:
Set Security zone
Made entry in Registry file
Set environment variable
Set default zoom size to 100 Please guide what should i do.
This code is working fine in firefox
Try this.
Enable protected mode for all zones in IE browser. It should be checked for all zones.
It worked for me.

How to load primefaces dialog in selenium?

i am trying to load primefaces dialog inside selenium test as follows:
-the primefaces code:
<p:commandLink id="iam_interested1" styleClass="iam_interested"
oncomplete="signUpDialog.show()"
actionListener="#{leadsBean.initSaveAction()}"
update=":betasignup">
I'm interested
</p:commandLink>
-the generate code for above primefaces code is:
<a id="headerForm:iam_interested1" href="#" class="ui-commandlink ui-widget iam_interested" onclick="PrimeFaces.ab({source:'headerForm:iam_interested1',update:'betasignup',oncomplete:function(xhr,status,args){signUpDialog.show();}});return false;">
I'm interested
</a>
the selenium code:
#Test
public void test() throws InterruptedException {
driver.get("http://localhost:8080/MyApp/index.xhtml");
WebElement dialogLink = driver.findElement(By
.className("iam_interested"));
dialogLink.click();
String currentWindowHandle = driver.getWindowHandle();
String popupWindowHandle = getPopupWindowHandle(driver,dialogLink);
driver.switchTo().window(popupWindowHandle);
(new WebDriverWait(driver, 5)).
until(ExpectedConditions.elementToBeClickable(By.className("ui-dialog-titlebar-close")));
driver.findElement(By.className("ui-dialog-titlebar-close")).click();
driver.switchTo().window(currentWindowHandle);
}
String getPopupWindowHandle(WebDriver driver, WebElement element) {
String popupHandle = null;
int maxTimeToWait = 5000;
int timeInterval = 1000;
int timeElasped = 0;
int attempt;
// get all the window handles before the popup window appears
Set<String> beforePopup = driver.getWindowHandles();
// click the link which creates the popup window
element.click();
System.out.println("element clicked");
attempt = 1;
while (timeElasped < maxTimeToWait) {
// get all the window handles after the popup window appears
Set<String> afterPopup = driver.getWindowHandles();
// remove all the handles from before the popup window appears
afterPopup.removeAll(beforePopup);
// there should be only one window handle left
if (afterPopup.size() == 1) {
System.out.println("Popup window found");
popupHandle = (String) afterPopup.toArray()[0];
break;
}
try {
Thread.sleep(timeInterval);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
timeElasped = timeInterval * attempt;
attempt++;
}
if (popupHandle.isEmpty() || popupHandle == null) {
System.out.println("No Popup Window found");
}
return popupHandle;
}
but the dialog doesn't load, and instead i get the exception:
org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: Element cannot be scrolled into view:http://localhost:8080/MyApp/betasignup_index.xhtml#
Command duration or timeout: 40 milliseconds
Build info: version: '2.33.0', revision: '4ecaf82108b2a6cc6f006aae81961236eba93358', time: '2013-05-22 12:00:17'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_25'
Session ID: 1ff0ca5a-5906-412f-b2a7-6e170a7d8932
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, browserConnectionEnabled=true, nativeEvents=true, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=21.0}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:191)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:79)
at com.motivosity.selenium.HomeTest.addingOneUser(HomeTest.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:80)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:47)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:355)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
please advise how to resolve it.
Issue was that the generated <a> component has multiple generated classes beside the declared one, so when i tried to get the link element by id instead, and do normal click, everything works fine:
WebElement dialogLink = driver.findElement(By
.id(dialogLinkId));
dialogLink.click();

How can i run my scenario with chrome using junit4 and selenium webdriver

In 2 days ago a was used this scenario and it works but know all time she didn't I don't know why, I use Selenium webdriver and junit4
so this my scenario and how i run chrome-driver with cmd and the error
package com.example.test;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class SearchWithCH {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
#Before
public void setUp() throws Exception {
driver = new RemoteWebDriver(DesiredCapabilities.chrome());
baseUrl = "http://localhost:8080/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void testUntitled() throws Exception {
driver.get(baseUrl + "/myapp/pages/accueil/login.xhtml#loaded");
driver.findElement(By.id("login")).clear();
driver.findElement(By.id("login")).sendKeys("login");
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys("password");
driver.findElement(By.id("loginButton")).click();
driver.findElement(By.xpath("//*[#id='mainMenu']/ul/li[2]/a")).click();
driver.findElement(By.xpath("//*[#id='menu_contact_search']")).click();
driver.findElement(By.id("formRecherche:nom")).clear();
driver.findElement(By.id("formRecherche:nom")).sendKeys("Jean");
driver.findElement(By.id("formRecherche:button_recherche")).click();
try {
assertTrue(driver.findElement(By.xpath("//*[#id='panel_contact_id_header']/span")).getText().matches("^[\\s\\S]*Contact : 9673 [\\s\\S]*$"));
} catch (Error e) {
verificationErrors.append(e.toString());
}
}
#After
public void tearDown() throws Exception {
//driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
}
and i was run chrome driver with
> java -jar selenium-server-standalone-2.30.0.jar -Dwebdriver.chrome.driver=C:\Users\lenovo\Desktop\Projet\chromedriver_win_26.0.1383.0\chromedriver.exe
but i have this error
> org.openqa.selenium.WebDriverException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list
Command duration or timeout: 130 milliseconds
Build info: version: '2.30.0', revision: 'dc1ef9c', time: '2013-02-19 00:15:57'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_13'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:129)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:119)
at com.QD2.Search.SearchWithCH.setUp(SearchWithCH.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list
at com.google.common.base.Preconditions.checkState(Preconditions.java:176)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:75)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:129)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.server.DefaultDriverFactory.callConstructor(DefaultDriverFactory.java:57)
at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:51)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:213)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:167)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
First start selenium server with below command
java -Dwebdriver.chrome.driver=latest\chromedriver.exe -jar selenium-server-standalone-2.31.0.jar
And then use below logic to create chrome driver instance
System.setProperty("webdriver.chrome.driver", "D:\\selenium\\latest\\chromedriver.exe");
DesiredCapabilities dc=new DesiredCapabilities();
dc.setBrowserName("chrome");
driver=new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),dc);
And run your test case using driver instance
driver.get("http://www.google.com");
try adding to the code before you initialize the Chromedriver:
System.setProperty("webdriver.chrome.driver", "C:\\Users\\lenovo\\Desktop\\Projet\\chromedriver_win_26.0.1383.0\\chromedriver.exe");
EDIT
Regarding your comments. Try this:
Press Ctrl + Alt + Del
Choose Task Manager
Switch to Processes
Sort by Name
Kill all "chromedriver" processes
Optionally: Restart computer
Try again
BTW, do you have Chrome installed?
EDIT2
Now I realised, that you are using RemoteWebDriver! So you have to start hub and node like this:
1st the hub:
java -jar lib/selenium-server-standalone-2.31.0.jar -role hub
2nd the node:
java -jar selenium-server-standalone-2.31.0.jar -role node -hub http://localhost:4444/grid/register -maxSession 15 -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=15 -Dwebdriver.chrome.driver=C:\Users\lenovo\Desktop\Projet\chromedriver_win_26.0.1383.0\chromedriver.exe
And then run your test