Unable to locate element though it is visible in WebPage - java

I am doing Selenium Webdriver automation using Java.
Please find the attached HTML extract of a web page http://1drv.ms/1CMtRxd and find the UI of the same http://1drv.ms/1JzXarv.
From the html, understand that all UI elements are constructed within a Table and the issue identified here is, unable to find the elements which are present in Right hand side table.
However, there is no issue on locating and using the elements present on left-hand side table within automation scripts.
Could you advise what is the difference between these two tables and why I’m unable to find the elements of Right hand side table during playback.
Also, could someone kindly help me to resolve this issue, please.
Please find the code extract:
(Coded with Page Object Model)
In POM Class:
#Test(description = "Test to Track the Order")
public void searchOrder() throws Exception
{
SearchRequest searchReq = PageFactory.initElements(wd, SearchRequest.class);
wd.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
searchReq.enterTrackingID("161471");
searchReq.clickSearchButton();
}
In Page Factory Class:
public class SearchRequest
{
#FindBy(how = How.ID, using = "cpportal:searchByID")
public WebElement trackingID;
public void enterTrackingID(String trackingID)
{
this.trackingID.clear();
this.trackingID.sendKeys(trackingID);
}
#FindBy(how = How.NAME, using = " cpportal:j_idt56 ")
public WebElement search;
public void clickSearchButton()
{
this.search.click();
}
}
Exception Thrown:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"cpportal:searchByID"}
Command duration or timeout: 10.12 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-27 00:00:10'
System info: host: 'inl-279930-1', ip: '10.13.136.53', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_55'
*** Element info: {Using=id, value=cpportal:searchByID}
Session ID: 3c404b65-ba64-435d-8395-53c262eff602
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=37.0.2}]
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:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:393)
at org.openqa.selenium.By$ById.findElement(By.java:214)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344)
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:59)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:37)
at com.sun.proxy.$Proxy8.clear(Unknown Source)
at com.cgi.hqn.liveref.pageobjects.SearchRequest.enterTrackingID(SearchRequest.java:17)
at com.cgi.hqn.liveref.test.CreateSOSL.searchOrder(CreateSOSL.java:176)
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:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"cpportal:searchByID"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-27 00:00:10'
System info: host: 'inl-279930-1', ip: '10.13.136.53', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_55'
Driver info: driver.version: unknown
at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/SUBRAM~1/AppData/Local/Temp/anonymous5667416437314785176webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:10271)
at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/SUBRAM~1/AppData/Local/Temp/anonymous5667416437314785176webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:603)

This could be an ajax element. Element is visible after a while.
What is the return value of-:
trackingID.isDisplayed();
This could be avoided by Implicit wait
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
or by WebDriver wait
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(trackingID));
Hope that helps

Related

How to click post button in Facebook groups?, webdriver Java

I also cannot click this button with the below code, i've tried:
driver.navigate().to(groupname);
Thread.sleep(3000);
driver.findElement(By.name("xhpc_message_text")).sendKeys(LinkYT+"\n");
Thread.sleep(3000);
driver.findElement(By.xpath("\\button\\span[.=\"Post\"]")).click();
I've used also waits and cssSelectors but cannot manage to click the button. I'm surely doing something wrong
Do you you have a suggestion?
<button class="_1mf7 _4jy0 _4jy3 _4jy1 _51sy selected _42ft" data-
testid="react-composer-post-button" type="submit" value="1"><img alt=""
class="_3-8_ _5gm4 img"
src="https://www.facebook.com/rsrc.php/v3/yb/r/GsNJNwuI-UM.gif" data-
testid="react-composer-throbber" width="16" height="11"><span
class="">Post</span></button>
ex for one of my tries, all have same no such element exection. so xpath,css selector etc i get them wrong for this button...
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no
such element: Unable to locate element:
{"method":"xpath","selector":"//button[#type='submit']
[contains(text(),'Post')]"}
(Session info: chrome=61.0.3163.100)
(Driver info: chromedriver=2.30.477700
(0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 10.0.15063
x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 46 milliseconds
For documentation on this error, please visit:
http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'INTERN2017-37', ip: '10.6.220.24', os.name: 'Windows
10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false,
mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome=
{chromedriverVersion=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),
userDataDir=C:\Users\LUCIAN~1.PAT\AppData\Local\Temp\scoped_dir19996_28709},
takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false,
handlesAlerts=true, hasTouchScreen=false, version=61.0.3163.100,
platform=XP, browserConnectionEnabled=false, nativeEvents=true,
acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true,
browserName=chrome, takesScreenshot=true, javascriptEnabled=true,
cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 2bbb3a860bbafbca888b4a9c5af20029
*** Element info: {Using=xpath, value=//button[#type='submit']
[contains(text(),'Post')]}
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)
manged to do it with:
WebElement elem = driver.findElement(By.xpath("//button[#type='submit']//span[contains(text(),'Post')]"));
Actions actions = new Actions(driver);
actions.moveToElement(elem).click().perform();
Your answer is correct but as I guess you can also use xpath using SPAN directly like this
WebElement elem = driver.findElement(By.xpath("//span[contains(text(),'Post')]"));
Actions actions = new Actions(driver);
actions.moveToElement(elem).click().perform();

org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM

I'm getting "StaleElementReferenceException" when selecting an option from the dropdown and get it as string. I'm very disappointed with the issue for last two days and I didn't get any best suggestion to sort out my issue. I'm very new to selenium, Please help me to sort out this issue.
public static WebElement prepProduct(WebDriver driver) throws InterruptedException
{
WebDriverWait wait = new WebDriverWait(driver,20);
Boolean enable=driver.findElement(By.xpath(".//*[#id='batch-update-prep-owner']")).isEnabled();
if(enable.TRUE)
{
Select whoPrepsMerchant= new Select(driver.findElement(By.xpath(".//*[#id='prep-items']/tr[2]/td[5]/select")));
whoPrepsMerchant.selectByIndex(new Random().nextInt(whoPrepsMerchant.getOptions().size()));
String merchant=whoPrepsMerchant.getFirstSelectedOption().getText();
Thread.sleep(3000);
String whoPrepsvalue=(driver.findElement(By.xpath(".//*[#id='prep-items']/tr[2]/td[7]/span"))).getText();
System.out.println("outer");
if(merchant.equalsIgnoreCase("Amazon"))
{
System.out.println("inner");
if(!whoPrepsvalue.equalsIgnoreCase("--"))
{
System.out.println("innerone");
Thread.sleep(3000);
driver.findElement(By.xpath(".//*[#id='continue-plan']")).click();
}
}
else
{
if(whoPrepsvalue.equalsIgnoreCase("--"))
{
System.out.println("innertwo");
Thread.sleep(3000);
driver.findElement(By.xpath(".//*[#id='continue-plan']")).click();
}
}
}
else
{
Thread.sleep(3000);
driver.findElement(By.xpath(".//*[#id='continue-plan']")).click();
}
return element;
}
Error Log:
org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM
Command duration or timeout: 15 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '3.0.0-beta4', revision: '3169782', time: '2016-09-29 10:29:23 -0700'
System info: host: '7531HY1', ip: '10.45.183.77', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=45.4.0, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 2eb3cd2b-e2e0-4efb-8b4c-3eb08f00ed45
*** Element info: {Using=tag name, value=option}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
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:636)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:284)
at org.openqa.selenium.remote.RemoteWebElement.findElements(RemoteWebElement.java:203)
at org.openqa.selenium.remote.RemoteWebElement.findElementsByTagName(RemoteWebElement.java:280)
at org.openqa.selenium.By$ByTagName.findElements(By.java:327)
at org.openqa.selenium.remote.RemoteWebElement.findElements(RemoteWebElement.java:179)
at org.openqa.selenium.support.ui.Select.getOptions(Select.java:70)
at org.openqa.selenium.support.ui.Select.getFirstSelectedOption(Select.java:94)
at NAGamma.SellerCentralPOM.prepProduct(SellerCentralPOM.java:85)
at NAGamma.Regression.main(Regression.java:40)
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: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)
Caused by: org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '3.0.0-beta4', revision: '3169782', time: '2016-09-29 10:29:23 -0700'
System info: host: '7531HY1', ip: '10.45.183.77', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_111'
Driver info: driver.version: unknown
at <anonymous class>.fxdriver.cache.getElementAt(resource://fxdriver/modules/web-element-cache.js:9531)
at <anonymous class>.Utils.getElementAt(file:///C:/Users/kesavamp/AppData/Local/Temp/anonymous980588199586178216webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:9916)
at <anonymous class>.FirefoxDriver.prototype.findElementsInternal_(file:///C:/Users/kesavamp/AppData/Local/Temp/anonymous980588199586178216webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:11205)
at <anonymous class>.FirefoxDriver.prototype.findChildElements(file:///C:/Users/kesavamp/AppData/Local/Temp/anonymous980588199586178216webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:11226)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/kesavamp/AppData/Local/Temp/anonymous980588199586178216webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12698)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/Users/kesavamp/AppData/Local/Temp/anonymous980588199586178216webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12703)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/Users/kesavamp/AppData/Local/Temp/anonymous980588199586178216webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12645)
Try this
Declare at the global level
WebDriverWait wait = new WebDriverWait(driver, 5);
Before selecting option from Drop-down
// while the following loop runs, the DOM changes -
// page is refreshed, or element is removed and re-added
wait.until(presenceOfElementLocated(By.id("container-element")));
// now we're good - let's click the element
For selecting option from Drop-down.
driver.findElement(By.id("foo")).click();
You can use:
wait.until(ExpectedConditions.refreshed(ExpectedConditions.visibilityOf(Element)));
Please verify and let me know if this is working fine for you...

Junit: NoSuchElement Exception while running test only in remotewebriver

I am running 10 tests in parallel with 2 nodes using selenium grid , got an NoSuchElementException only in Remotewebdriver , but the same is working fine in normal firefox driver ,
I have definded my own threadpool executor class which holds two threads at a time , each thread starts its own Junit tests using Junitcore api.
below is the exception i recieved
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"login_element"}
Command duration or timeout: 1.28 seconds
Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_24'
Session ID: 5c94133a-5586-449c-b7f6-018bbd79a6d7
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotata
ble=false, locationContextEnabled=true, version=23.0.1, cssSelectorsEnabled=true, databaseEnabled=tr
ue, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=true, webStorageEnabled=true, ap
plicationCacheEnabled=true, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:
39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorIm
pl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
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.RemoteWebDriver.findElement(RemoteWebDriver.java:307)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByLinkText(RemoteWebDriver.java:356
)
at org.openqa.selenium.By$ByLinkText.findElement(By.java:241)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)
at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.openqa.selenium.support.events.EventFiringWebDriver$2.invoke(EventFiringWebDriver.jav
a:101)
at $Proxy1.findElement(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver.findElement(EventFiringWebDriver.
java:180)
at org.openqa.selenium.remote.server.handler.FindElement.call(FindElement.java:47)
at org.openqa.selenium.remote.server.handler.FindElement.call(FindElement.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:169)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Also tried a sample small tests , works fine without any exception , issue occurs only if i run my application
Please provide your inputs on this
Did you try to wait for the element? I would suggest you to use WebDriverWait
WebDriverWait wait = new WebDriverWait(driver,120/*timeout in seconds*/);
WebElement login = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("login_element")));
//do stuff with login

Element not visible in firefox as well as chrome

I am working in selenium webdriver 2.0, and I have to automate a script for running functional and cross-browser testing. I am getting an error of element not visible when I am trying to click on an element with the class .divAdvSearchFeildListName&[data-id='30001'] for a drop down.
The same code works fine for some drop-downs to select a country name and jurisdiction from the same page on the same page. The error I am getting is:
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 47 milliseconds
Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:22:56'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0_21'
Session ID: 2ca283f6-5703-4ef6-b07f-2dee99b531ab
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=22.0}]
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.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:79)
at com.anteambulo.SeleniumJQuery.Prog_Try_Six.automate(Prog_Try_Six.java:1112)
at com.anteambulo.SeleniumJQuery.Prog_Try_Six.hCueIgn(Prog_Try_Six.java:122)
at com.anteambulo.SeleniumJQuery.Prog_Try_Six.main(Prog_Try_Six.java:71)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Element is not currently visible and so may not be interacted with
Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:22:56'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0_21'
Driver info: driver.version: unknown
at <anonymous class>.fxdriver.preconditions.visible(file:///C:/DOCUME~1/155366/LOCALS~1/Temp/anonymous8998336689581680973webdriver-profile/extensions/fxdriver#googlecode.com/components/command_processor.js:7682)
at <anonymous class>.DelayedCommand.prototype.checkPreconditions_(file:///C:/DOCUME~1/155366/LOCALS~1/Temp/anonymous8998336689581680973webdriver-profile/extensions/fxdriver#googlecode.com/components/command_processor.js:10402)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/DOCUME~1/155366/LOCALS~1/Temp/anonymous8998336689581680973webdriver-profile/extensions/fxdriver#googlecode.com/components/command_processor.js:10421)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/DOCUME~1/155366/LOCALS~1/Temp/anonymous8998336689581680973webdriver-profile/extensions/fxdriver#googlecode.com/components/command_processor.js:10426)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/DOCUME~1/155366/LOCALS~1/Temp/anonymous8998336689581680973webdriver-profile/extensions/fxdriver#googlecode.com/components/command_processor.js:10366)
My code gets stuck at line number 6 in this code snippet. As you can see in the code I am trying to highlight that web element with a 5px solid yellow border:
jQuery EntitySearchTypeValue = browser.queryUntil(a1ValEntityDropDownList);
setCellName(26,0,a1ValEntityDropDownListLabel,sheetReportGeneration);
hCueExcel(1,1,26,sheetReportGeneration,browser,colNoForDiffBrowsers,EntitySearchTypeValue);
System.out.println("Login Button found");
// password.css("border", "none");
EntitySearchTypeValue.css("border", "5px solid yellow");
takescreenshot(a1ValFileNamePath,26,colNoForDifferentScreenShots,sheetSnapshotGeneration,workbook);
***EntitySearchTypeValue.get().click();***
// browser.findElement(By.className("divAdvSearchFeildListName&[data-id='30001']")).click();
// browser.getDrv().findElementByClassName("EntitySearchTypeValue&[data-id='30001']").click();
// browser.getDrv().findElementByCssSelector(".divAdvSearchFeildListName&[data-id='30001']").click();
// document.querySelector(".field[data-test]");
// browser.get()
// By cssSelector = By.cssSelector(".field[data-test='testytest']");
// or By.cssSelector(".field[data-test=testytest]")
// or By.cssSelector(".field[data-test]")
//bin.findElement(cssSelector).sendKeys("Hello");
try{
Thread.sleep(5000L);
}catch(Exception e){
}
The same code works fine in Firefox, but gets stuck at some point later in the code for other browsers. For Chrome it gets stuck in the beginning for the third drop-down in the same page. I have the selenium-server-standalone-2.32.0.jar which is the latest version.
This exception means that the element you are trying to click on is hidden. Make sure that the element is visible before click on it. You can add a wait if the element becomes visible after delay.
Apart from this you should check the system configuration and it should be compatible.

How to find the text under div class

I am using Internet Explorer as a browser to automate testing, using webdriver. My question being, how do I find the text under the div class?
My HTML looks like this:
<div class="welcome_text">
Text-Welcome Vijayanand
I have tried to use an XPath like this
WebElement webelement=driver.findElement(By.xpath("//div[#Class='welcome_text']/div"));
webelement.getText();
But I am getting the error shown below:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == //DIV[#Class='welcome_text']/DIV (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 656 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:23:22'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_05'
Session ID: 87815f2f-f6ff-4689-ac34-befb114acfe4
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{platform=WINDOWS, elementScrollBehavior=0, javascriptEnabled=true, enablePersistentHover=true, ignoreZoomSetting=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, version=8, cssSelectorsEnabled=true, ignoreProtectedModeSettings=true, requireWindowFocus=false, allowAsynchronousJavaScript=true, handlesAlerts=true, initialBrowserUrl=, nativeEvents=true, takesScreenshot=true}]
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.findElement(RemoteWebDriver.java:307)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:404)
at org.openqa.selenium.By$ByXPath.findElement(By.java:344)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)
at internetexplorerlaunch.IElaunch.main(IElaunch.java:44)
Try By.className() method as shown below.
WebElement webelement=driver.findElement(By.className("welcome_text"));
webelement.getText();
Your XPATH is wrong:
WebElement webelement=driver.findElement(By.xpath("//div[#Class='welcome_text']/div"));
webelement.getText();
It should be:
driver.findElement(By.xpath("//div[#class='welcome_text']"));

Categories