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
Related
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();
I am trying to select some values from a dropdown and have tries all the options : selectByIndex, selectByVisibleText, selectByValue but I am unable to select value on the page; tried different waits also but still getting get the below error :
Exception in thread "main" org.openqa.selenium.ElementNotVisibleException:
Element is not visible (WARNING: The server did not provide any stacktrace
information)
Command duration or timeout: 42 milliseconds
Build info: version: '3.0.0-beta3', revision: 'c7b525d', os.name: 'Windows
10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false,
appBuildId=20160726073904, version=, platform=XP, proxy={}, command_id=1,
specificationLevel=0, acceptSslCerts=false, browserVersion=48.0,
platformVersion=10.0, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384},
browserName=Firefox, takesScreenshot=true, takesElementScreenshot=true,
platformName=Windows_NT, device=desktop}]
Session ID: 83d79d14-527d-4a8e-a05e-01671d7b73f3
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:631)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:284)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
at org.openqa.selenium.support.ui.Select.setSelected(Select.java:324)
at org.openqa.selenium.support.ui.Select.selectByValue(Select.java:201)
at accessingForms.FormElements.main(FormElements.java:39)
Below is the snippet of my code, firefox version 48
driver.get("http://newtours.demoaut.com");
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("userName")));
driver.findElement(By.partialLinkText("here")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("country")));
System.out.println("wait statement executed");
Select CountryDrpDwn = new Select(driver.findElement(By.name("country")));
System.out.println("found the drop down");
Thread.sleep(1000);
CountryDrpDwn.selectByValue("3");
System.out.println("Selected by value mofo");
Thread.sleep(2000);
CountryDrpDwn.selectByVisibleText("ANTARCTICA ");
System.out.println("Antarctica Selected");
Thanks in advance for help
I have been trying to use Selenium sendkeys() without success using Chrome. I've researched similar questions here that seemed related without success. I can spawn the URL, invoke buttons (click()) but when I attempt to enter a value within a specific text field I get:
"Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot focus element."
Would appreciate any help. Thank you!
Here's a snippet of code:
WebElement titleBox = driver.findElement(By.xpath("//*[#id='root']/div/div[2]/div/div/div[2]/div[1]"));
titleBox.click();
titleBox.sendKeys("Test Survey Title");
Here's the stack trace:
Starting ChromeDriver 2.29.461585 (0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b) on port 43615
Only local connections are allowed.
May 26, 2017 3:42:50 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot focus element
(Session info: chrome=58.0.3029.110)
(Driver info: chromedriver=2.29.461585 (0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b),platform=Mac OS X 10.12.5 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 43 milliseconds
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'Enriques-MacBook-Pro.local', ip: '10.0.0.208', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.5', 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.29.461585 (0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b), userDataDir=/var/folders/55/jxcw642x4593njd3nnysck_80000gn/T/.org.chromium.Chromium.4miVBB}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=58.0.3029.110, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: c0d55118bf095a12cb6e105b581b149e
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:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:671)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:272)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:96)
at LaunchChrome.main(LaunchChrome.java:36)
You can try following code using actions class to have focus on your element before you can interact with it:
WebElement titleBox = driver.findElement(By.xpath("//*#id='root']/div/div[2]/div/div/div[2]/div[1]"));
Actions action = new Actions(driver);
action.moveToElement(titleBox).build().perform();
titleBox.click();
titleBox.sendKeys("Test Survey Title");
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.
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']"));