Elements are not identified properly, whats wrong? - java

in my Angular application i am identifying an element with its id. But its not recognizing during the execution and below are my details.
In my screen, i have a Loan number control with loan value and its checkbox as checked state. I have to find out whether after the screen launch, this loan number is checked or not. I have scripted with its identified (id) but during the execution it not recognized and it throws 'Element not visible' error. Any help please..
<section class="verification-element" data-ng-show="$ctrl.value || $ctrl.vmodel=='isIvrVerified'" aria-hidden="false">
<div class="verification-element--nameValue" data-ng-switch="$ctrl.type">
<label for="loanNumberid" class="verification-element__name ng-binding">LOAN NUMBER</label>
<!-- ngSwitchWhen: address -->
<!-- ngSwitchWhen: percentage -->
<!-- ngSwitchWhen: select -->
<!-- ngSwitchDefault: --><span class="verification-element__value ng-binding ng-scope" id="loanNumberValueId" data-ng-switch-default="">0553101437</span><!-- end ngSwitchWhen: -->
</div>
<div class="verification-element--checkbox saturn-checkbox">
<input class="checkBoxFirstPanel ng-pristine ng-untouched ng-valid ng-empty" type="checkbox" name="loanNumber" id="loanNumberid" data-ng-checked="true" data-ng-model="$ctrl.thing" data-ng-click="$ctrl.checkedElement({name: $ctrl.vmodel, value: $ctrl.thing})" checked="checked" aria-invalid="false" style="">
<label for="loanNumberid"></label>
</div>
</section>
When i checked with my developer, he says that he has put 'id' for this checkbox control as "loanNumberid" i also scripted with that. but when i inspect it actually shows the <lable> control and i am confused on this. here is my selenium code
#FindBy(id = "loanNumberid")
public static WebElement chkloan;
chkloan.click();
and i get the error as...
org.openqa.selenium.ElementNotVisibleException: element not visible
(Session info: chrome=56.0.2924.76)
(Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 23 milliseconds
Build info: version: '2.43.1', revision: '5163bceef1bc36d43f3dc0b83c88998168a363a0', time: '2014-09-10 09:43:55'
System info: host: 'MUS5CG6030CWS', ip: '10.219.18.222', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_92'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed), userDataDir=C:\Users\par964\AppData\Local\Temp\scoped_dir17000_14241}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=56.0.2924.76, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: a8514260e4e55f5ff09b60d0196223f4
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: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.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:79)
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.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:50)
at com.sun.proxy.$Proxy15.click(Unknown Source)
at com.capitalone.Pages.NewVerificationModal.clickCheckBoxes(NewVerificationModal.java:360)
at com.capitalone.Steps.Saturn_Login.selectElements(Saturn_Login.java:490)
at ?.And I select fields on verification panel(src/test/resources/feature/SmokeCICD/NotesMemo.feature:12)

Make sure that there are no elements with same ID in the DOM model
Make sure that element is not overlapped with smthn else
Try clicking either JS, either using Actions

Related

Unable to select a value from dropdown inside dynamic webtable in Internet Explorer

I am trying to click on a dropdown in a webpage which is located inside a dynamic webtable.
I have tried to locate and select an option using driver.findelement, actions.movetoElement, javascript, Robot keypress but no luck.
public void selectFromDropDown(String value) throws Exception
{
List<WebElement> elem = driver.findElements(By.xpath("//tbody[#id='tbodyAlternateIds']//select"));
for(int i=1;i<elem.size()-1;i++) {
System.out.println("Element Size>>>>>>>>" + elem.size());
WebElement Identifiers = driver.findElement(By.xpath("//select[#id='alternateIds["+i+"].type.description']"));
Select select = new Select(Identifiers);
if(select.getFirstSelectedOption().getText().isEmpty()) {
if(!(select.getFirstSelectedOption().getAttribute("value").equalsIgnoreCase(value))){
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById('alternateIds["+i+"].type.description').value = "+value+";");
}
}
}
}
My DOM looks like the below
<SELECT id=alternateIds[2].type.description class=smalltext name=alternateIds[2].type.code value="">
<OPTION selected></OPTION>
<OPTION value=AML>AML</OPTION>
<OPTION value=ALC>Alacra ID</OPTION>
<OPTION value=BOS>BOSS</OPTION>
<OPTION value=BKA>Bankers Almanac ID</OPTION>
`
`
`
`
</SELECT>
Error message from the log is as follows:
org.openqa.selenium.JavascriptException: JavaScript error (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.5.3', revision: 'a88d25fe6b', time: '2017-08-29T12:42:44.417Z'
System info: host: 'VKRDAP0009714', ip: '30.206.79.17', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_202'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, enablePersistentHover=false, ie.forceCreateProcessApi=false, pageLoadStrategy=normal, unhandledPromptBehavior=dismiss, 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:45547/, takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=false, platformName=WINDOWS, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=dismiss}]
Session ID: f0f347a8-b5c6-4bf1-bd89-576498a53872
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:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:82)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.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:646)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:582)
at com.bofa.ivv.application.driver.tandem.cucumber.step_definitions.CreateParty.selectFromDropDown(CreateParty.java:434)
The ID in select is dynamic. I can click on New button and proceed with list of dropdown boxes. And hence each dropdown box ID is categorized and incremented by [1], [2] etc... (alternateIds[1].type.description)
You need to surround your value with quotation marks like:
js.executeScript("document.getElementById('alternateids[" + i + "].type.description').value='" + value + "'");
Why at all you are going for this JavaScript call? There is Select.selectByValue() function which does the same
Consider migrating your test to use Page Object Model design pattern

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();

Selenium web driver cannot click a button while element is visible and clickable, throws org.openqa.selenium.ElementNotInteractableException

I have following menu bar which I try to test with selenium web driver:
<div class="text-center">
<div class="btn-group pull-left">
<button type="button" class="btn btn-default" id="id-home_prevButton" style="min-height:10px;min-width:10px" hidden="false"><span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span>
</button><button type="button" class="btn btn-default" id="id-home_nextButton" style="min-height:10px;min-width:10px" hidden="false"><span class="glyphicon glyphicon-arrow-right" aria-hidden="true"></span></button>
</div>
<span class="span-title" id="id-home_title">Home</span>
<div class="btn-group pull-right">
<button type="button" class="btn btn-default" id="id-home_infoButton" hidden="false"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span></button>
<div class="btn-group">
<button type="button" id="id-home_dropDownButton" class="btn btn-default dropdown-toggle" data-toggle="dropdown" hidden="false">
<i class="glyphicon glyphicon-align-justify"></i><span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right simple-title-dropdown" role="menu">
<li>Home</li>
</ul>
</div>
</div>
</div>
Button ids are unique.
Selenium scala code clicking the button is:
def wEPrint(description: String, wE: WebElement): String = {
s"$description = wE.getTagName: ${wE.getTagName} wE.getText: ${wE.getText} wE.getSize: ${wE.getSize} wE.isDisplayed: ${wE.isDisplayed} wE.isEnabled: ${wE.isEnabled} wE.isSelected: ${wE.isSelected}"
}
...
log.debug("Find id-home_prevButton")
import org.openqa.selenium.support.ui.WebDriverWait
val waitPrevButton = new WebDriverWait(driver, 20)
val prevButton = driver.findElement(By.id("id-home_prevButton"))
log.debug(wEPrint("prevButton",prevButton))
waitPrevButton.until(ExpectedConditions.visibilityOfElementLocated(By.id("id-home_prevButton")))
log.debug("id-home_prevButton.click")
prevButton.click()
sbt console output is:
22:49:11.378 [run-main-3] DEBUG com.example.selex.MWLExp$ - Find id-home_prevButton
22:49:11.539 [run-main-3] DEBUG com.example.selex.MWLExp$ - prevButton = wE.getTagName: button wE.getText: wE.getSize: (40, 34) wE.isDisplayed: true wE.isEnabled: true wE.isSelected: false
22:49:11.588 [run-main-3] DEBUG com.example.selex.MWLExp$ - id-home_prevButton.click
[error] (run-main-3) org.openqa.selenium.ElementNotInteractableException:
[error] Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
[error] System info: host: 'tra', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-72-generic', java.version: '1.8.0_121'
[error] Driver info: org.openqa.selenium.firefox.FirefoxDriver
[error] Capabilities [{moz:profile=/tmp/rust_mozprofile.T6j4aNCkep6a, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0.0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=53.0, platformVersion=4.4.0-72-generic, moz:processID=51151.0, browserName=firefox, javascriptEnabled=true, platformName=linux}]
[error] Session ID: 1349d85f-d360-4725-963c-f6ec277e308c
org.openqa.selenium.ElementNotInteractableException:
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'tra', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-72-generic', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=/tmp/rust_mozprofile.T6j4aNCkep6a, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0.0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=53.0, platformVersion=4.4.0-72-generic, moz:processID=51151.0, browserName=firefox, javascriptEnabled=true, platformName=linux}]
Session ID: 1349d85f-d360-4725-963c-f6ec277e308c
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.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.click(RemoteWebElement.java:82)
at com.example.selex.MWLExp$.run01(MWLExp.scala:92)
at simple.MainJVM$.main(DemoJVM.scala:44)
at simple.MainJVM.main(DemoJVM.scala)
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)
Selenium test code can find the button, it is displayed and enabled, visibilityOfElementLocated succeeds but clicking throws ElementNotInteractableException.
When I run the app without selenium, button is visible and I can click it and it works without any errors.
In selenium IDE clicking the button works OK. Selenium IDE Java code for clicking the button is:
driver.findElement(By.id("id-home_prevButton")).click();
EDIT
I modified the code slightly:
import org.openqa.selenium.support.ui.WebDriverWait
val waitPrevButton = new WebDriverWait(driver, 20)
val prevButton = driver.findElement(By.id("id-home_prevButton"))
log.debug(wEPrint("prevButton",prevButton))
waitPrevButton.until(ExpectedConditions.visibilityOfElementLocated(By.id("id-home_prevButton")))
log.debug("id-home_prevButton.click")
//prevButton.click()
//prevButton.sendKeys(Keys.RETURN)
prevButton.sendKeys(Keys.ENTER)
And now the exception message is:
23:30:56.497 [run-main-6] DEBUG com.example.selex.MWLExp$ - Find id-home_prevButton
23:30:56.735 [run-main-6] DEBUG com.example.selex.MWLExp$ - prevButton = wE.getTagName: button wE.getText: wE.getSize: (40, 34) wE.isDisplayed: true wE.isEnabled: true wE.isSelected: false
23:30:56.798 [run-main-6] DEBUG com.example.selex.MWLExp$ - id-home_prevButton.click
[error] (run-main-6) org.openqa.selenium.ElementNotInteractableException: Element is not visible
[error] Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
[error] System info: host: 'tra', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-72-generic', java.version: '1.8.0_121'
[error] Driver info: org.openqa.selenium.firefox.FirefoxDriver
[error] Capabilities [{moz:profile=/tmp/rust_mozprofile.gBopOPHPUrCL, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0.0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=53.0, platformVersion=4.4.0-72-generic, moz:processID=54936.0, browserName=firefox, javascriptEnabled=true, platformName=linux}]
[error] Session ID: eba7323c-6412-4ed7-a91f-3f897b3ec83f
org.openqa.selenium.ElementNotInteractableException: Element is not visible
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'tra', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-72-generic', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=/tmp/rust_mozprofile.gBopOPHPUrCL, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0.0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=53.0, platformVersion=4.4.0-72-generic, moz:processID=54936.0, browserName=firefox, javascriptEnabled=true, platformName=linux}]
Session ID: eba7323c-6412-4ed7-a91f-3f897b3ec83f
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.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.sendKeys(RemoteWebElement.java:96)
at com.example.selex.MWLExp$.run01(MWLExp.scala:93)
at simple.MainJVM$.main(DemoJVM.scala:44)
at simple.MainJVM.main(DemoJVM.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
So now it says that element is not visible although visibilityOfElementLocated has succeeded and it is displayed and enabled.
What's the reason for this exception and how to fix it?
Thank you for your support.
Use javascriptExecutor to click the element by embedding javascript. By using javascript executor we can run the javascript on the driver.
WebElement element = driver.findElement(By.id("id-home_prevButton");
((JavascriptExecutor)driver).executeScript("arguments[0].click();", element);
I also had a similar problem which was fixed by:
String id = element.getAttribute("id");
((JavascriptExecutor)driver).executeScript("$('#id').click();");
With Selenium Advanced User Interaction API mentioned e.g. here:
I could fix this issue. Modified selenium code is as follows:
import org.openqa.selenium.support.ui.WebDriverWait
val waitPrevButton = new WebDriverWait(driver, 20)
val prevButton = driver.findElement(By.id("id-home_prevButton"))
log.debug(wEPrint("prevButton",prevButton))
waitPrevButton.until(ExpectedConditions.visibilityOfElementLocated(By.id("id-home_prevButton")))
log.debug("id-home_prevButton.click")
//prevButton.click()
//prevButton.sendKeys(Keys.RETURN)
//prevButton.sendKeys(Keys.ENTER)
new Actions(driver).moveToElement(prevButton).click().perform()
This fixes the issue but I would still like to know the reason for the ElementNotInteractableException and why selenium complained "Element is not visible" after successfull visibilityOfElementLocated test. Any ideas?
This issue will be resolve by simply using Implicit wait because web page loaded page completely then its find elements.
driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); driver.get("URL");
I met the same issue. I captured the same element by using different Xpath and it worked. I also don't know why. Below is my case:
//a[contains(text(),'%s')] -> did not work.
//a//span[contains(text(),'%s')] -> worked.
This is my HTML code:
<a data-gtm-event="mbn-event-link" data-gtm-category="mbn-listing" data-gtm-action="home-category-l0-c3" href="/mua-ban-nha-dat-cho-thue-toan-quoc-l0-c3" title="Bất động sản ">
<span class="clearfix">
<span class="category-icon"><span class="icon icon-cat-3"></span></span>
<span class="category-name">Bất động sản</span>
</span>
</a>
<span class="clearfix">
<span class="category-icon"><span class="icon icon-cat-3"></span></span>
<span class="category-name">Bất động sản</span>
</span>

Java Selenium Webdriver: Element not clickable

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();

Current IE doesn't support file upload using Selenium Webdriver 2.42.000

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

Categories