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();
Related
I am trying to find the xpath for the following code. But it is showing some errors.
inspect element is:
<BUTTON title="Create Customer" class="SBCUSTMENU awbButton" id=C2_W10_V11_btnCREATE_CUSTMC onmouseout=javacript:awbImgButtonMouseOut(this); onmousedown=javacript:awbImgButtonMouseDown(this); onmouseup=javacript:awbImgButtonMouseUp(this); onclick="javascript:if(awbBtnActive(this)){if (awbAddMonitorIdsToHttp(['MONITOR_JOURNEY','','MONITOR_STEP',''])){htmlbSubmitLib('htmlb',this,'htmlb:button:click:null','myFormId','C2_W10_V11_btnCREATE_CUSTMC','onclick_CREATE_CUSTMC',0);}}return false;" type=button awbClass="awbButton SBCUSTMENU"> </BUTTON>
driver.findElement(By.id("C2_W10_V11_btnCREATE_CUSTMC")).click();
I am expecting the below error
Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for visibility of element located by By.id: C2_W10_V11_btnCREATE_CUSTMC
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'PC404441', ip: '10.27.101.9', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_192'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, ie.enableFullPageScreenshot=true, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.forceShellWindowsApi=false, pageLoadStrategy=normal, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:10768/, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss}]
You might need to induce a WebDriverWait, if the element you are clicking is dynamically generated:
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;
(new WebDriverWait(driver, 10)).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button[title='Create Customer']")).click();
First check if the the element is present in FRAME or not - if it is present -> in that case you need to first switch to that frame and then perform the action.
driver.switchTo.frame("");
// perform the action
If not inside frame then you can use Explicit Waits:
WebDriverWait wait = new WebDriverWait(driver, waitTime);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.XPath("")))
OR
WebDriverWait wait = new WebDriverWait(driver, waitTime);
wait.until(ExpectedConditions.elementToBeClickable(locator));
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 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();
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']"));