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']"));
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();
Code -
Select Gender = new Select(driver.findElement(By.xpath("//select[#id='gender']")));
Gender.selectByValue("Male");
Error -
`Exception in thread "main" org.openqa.selenium.WebDriverException: **Permission denied to access property "invoke"**
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'COMP2-PC', ip: '192.168.1.9', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_91'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, appBuildId=20161123182536, version=50.0.1, platform=XP, proxy=Proxy(), command_id=1.0, specificationLevel=0.0, acceptSslCerts=false, processId=2380.0, browserVersion=50.0.1, platformVersion=6.1, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=firefox, takesScreenshot=true, takesElementScreenshot=true, javascriptEnabled=true, platformName=windows_nt}] Session ID: c1e4da76-9f21-45aa-a1b8-f21a9e8dd088
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.http.W3CHttpResponseCodec.createException
(W3CHttpResponseCodec.java:150)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode
(W3CHttpResponseCodec.java:115)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode
(W3CHttpResponseCodec.java:45)
at org.openqa.selenium.remote.HttpCommandExecutor.execute
(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute
(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute
(RemoteWebDriver.java:637)
at org.openqa.selenium.remote.RemoteWebElement.execute
(RemoteWebElement.java:272)
at org.openqa.selenium.remote.RemoteWebElement.getAttribute
(RemoteWebElement.java:124)
at org.openqa.selenium.support.ui.Select.<init>(Select.java:52)
at AppInformationTest.main(AppInformationTest.java:70) `
While trying to automate (Selecting a dropdown value) with selenium webdriver I ran into this problem.
Tools Versions are*:
Java - 1.8.0_91,
Eclipse - Oxygen Release (4.7.0),
Mozilla Firefox-50.01,
Gecko driver-v0.17.0-win64 ....Please help me to sort out!
It is browser specfic issue , try it with Chrome. Follow this link to see more
Reference Link for your issue
I tried verifying an element present onpage using isDisplayed()
it returns true.
Tried Actions class and JavascriptExecutor but no luck
Able to find an element but it is not clickable.
org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (48, 339). Other element would receive the click: <div modal-render="true" tabindex="-1" role="dialog" class="modal fade ng-isolate-scope ng-animate ng-leave ng-leave-active" uib-modal-animation-class="fade" modal-in-class="in" ng-style="{'z-index': 1050 + index*10, display: 'block'}" uib-modal-window="modal-window" size="md" index="0" animate="animate" modal-animation="true" data-ng-animate="2" style="z-index: 1050; display: block;">...</div>
(Session info: chrome=51.0.2704.103)
(Driver info: chromedriver=2.7.236900,platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 68 milliseconds
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_91'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, chrome=takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=51.0.2704.103, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 58f38b1bcae44097a4dad7378ba32e35
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)
There's a DIV modal in the way of the click. It's explained in the error message. Dismiss it or otherwise handle it.
Try to use ExpectedConditions from WebDriverWait class to check the Clickable property of the element.
Many a time I have seen that element.isDisplayed/isEnabled didn't work, but this worked fine.
Eg Code:
Webdriver driver;
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(By.className("xyz"))).click();
Currently I was able to upload the file using selenium webdriver version 2.42.00 with browser chrome while I couldn't able to do it the same with Internet Explorer version 11.
driver.findElement(By.id("fileUpload")).sendKeys(filePath);
where id = fileUpload is for input element with type=file and this field is a hidden field.
Any thoughts on it:
org.openqa.selenium.ElementNotVisibleException: Element is not displayed (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 30 milliseconds
Build info: version: '2.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43ad8', time: '2014-10-23 13:11:40'
System info: host: 'XXXXXXX', ip: '192.168.12.24', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_40'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, enablePersistentHover=false, ie.forceCreateProcessApi=false, ie.usePerProcessProxy=false, ignoreZoomSetting=false, handlesAlerts=true, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=true, browserName=internet explorer, initialBrowserUrl=http://localhost:7704/ takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=dismiss}]
Session ID: cfa81fae-4ea2-43b9-9e3a-69135462fe82
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_40]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.8.0_40]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.8.0_40]
It is a known issue with IEDriver which is going to be resolved in next release. Hidden file input tag will not work on IE as it does on other browsers. See the issue logged here. I have answered a similar question here
EDIT
Here is the good news. Just confirmed the Selenium version 2.46 has the changes. See changelog. So upgrade and it should work
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