I am practicing Selenium-Webdriver and encounter the issue that the desirable element(text) is visible on web page, but I cannot click on it.
Trying to do check this element is displayed or not by command line "isDisplayed", and the console returns false result. I am a little bit confused that the text(please see the highlight on attached file) on web is visible but why cannot be clickable?
On this case, how can we perform some actions on it? could you please share your ideas and strategy to do.
Thank you so much.
Here is the web page:
http://www.lazada.com.ph/
My code is
System.setProperty("webdriver.chrome.driver", driver_path);
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("https://www.lazada.com.ph/");
//Click on Men's Fashion
WebElement loc = driver.findElement(By.xpath("//div[#data-qa-locator='brands-by-category-cats-item']/div[#data-tab-id='2']"));
Actions hover = new Actions(driver);
hover.moveToElement(loc).click().build().perform();
Error log:
false
Exception in thread "main" org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: (-2114, -93.0999984741211) is out of bounds of viewport width (1366) and height (659)
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:26.402Z'
System info: host: 'Lorem', ip: '192.168.30.1', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Users\Lorem\AppData\Local\Temp\rust_mozprofile.y3xzzu5rD0i5, rotatable=false, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, moz:headless=false, platform=XP, specificationLevel=0, moz:accessibilityChecks=false, acceptInsecureCerts=true, browserVersion=56.0.2, platformVersion=6.3, moz:processID=4724, browserName=firefox, javascriptEnabled=true, platformName=XP}]
Session ID: 893e64ce-b53c-4bec-9f98-14832e4b7151
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:422)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:185)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:120)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)
at org.openqa.selenium.remote.RemoteWebDriver.perform(RemoteWebDriver.java:652)
at org.openqa.selenium.interactions.Actions$BuiltAction.perform(Actions.java:638)
at basic.Wait.main(Wait.java:41)
The error says it all as follows :
org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: (-2114, -93.0999984741211) is out of bounds of viewport width (1366) and height (659)
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:26.402Z'
The WebElement which you are trying to click is Not Visible as it is out of the Viewport. As you have used Actions Class hence it shows MoveTargetOutOfBoundsException
You can consider the following code block to scroll the WebElement within the Viewport first then take help of JavascriptExecutor to click as follows :
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver();
driver.get("https://www.lazada.com.ph/");
//Click on Men's Fashion
WebElement elem = driver.findElement(By.xpath("//div[#class='c-category-tab c-brands-by-category__tab']/span[#class='c-category-tab__icon c-category-tab__icon_category-fashion']"));
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView();", elem);
((JavascriptExecutor)driver).executeScript("arguments[0].click();", elem);
It seems that you'r xpath giving more then one element .
try below code .
WebElement loc = driver.findElement(By.xpath("(//div[#data-qa-locator='brands-by-category-cats-item']/div[#data-tab-id='2'])[2]"));
Actions hover = new Actions(driver);
hover.moveToElement(loc).click().build().perform();
The problem is that your xpath return 3 elements. If you try the following code, you could notice this:
//Click on Men's Fashion
List<WebElement> loc = driver.findElements(By.xpath("//div[#data-qa-locator='brands-by-category-cats-item']/div[#data-tab-id='2']"));
System.out.println(loc.size());
int i=1;
for(WebElement we :loc)
{
System.out.println("innerText:" + we.getAttribute("innerText"));
System.out.println("getLocation: " + we.getLocation());
System.out.println("getText: " + we.getText());
System.out.println("getSize: " + we.getSize());
if(we.getText().contains("Men's Fashion"))
{
we.click();
}
System.out.println("------------ "+i+" -------------");
i++;
}
The output is:
3
innerText:Men's Fashion
getLocation: (-2210, 838)
getText:
getSize: (141, 118)
------------ 1 -------------
innerText:Men's Fashion
getLocation: (178, 838)
getText: Men's Fashion
getSize: (141, 118)
------------ 2 -------------
innerText:Men's Fashion
getLocation: (2567, 838)
getText:
getSize: (141, 118)
------------ 3 -------------
If you click the element with getText=Men's Fashion it works.
To be honest I don't know why the xpath return 3 elements. I hope someone give the answer.
There are so many ways to reach to this element. couple more below.
//span[#data-id=4]
//span[#data-tracking-nav-header="Men's Fashion"]
Related
I have a scenario where I 1st iframe (i.e parent iframe) which has one button on it and clicking on it another iframe gets open (child iframe). I am able to switch to Parent iframe but when I click on button and tries to interact with Child iframe I'm not able to do it. Can you suggest what should be the better approach to get this type of scenarios working?
My Script:
public class Iframe {
public static void main (String []args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", Constants.Chrome_Driver);
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://automation.cloudaccess.host/administrator");
driver.findElement(By.id("mod-login-username")).sendKeys("admin");
driver.findElement(By.id("mod-login-password")).sendKeys("admin#123");
driver.findElement(By.id("mod-login-password")).submit();
driver.findElement(By.linkText("Components")).click();
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.linkText("Messaging"))).build().perform();
driver.findElement(By.linkText("New Private Message")).click();
driver.findElement(By.className("wf-editor-header")).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[#id=\"jform_message_imgmanager\"]"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[contains(#src,'&plugin=imgmanager')]")));
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[#id=\"browser-actions\"]/a[#id=\"help\"]"))).click();
driver.switchTo().defaultContent();
new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[#id=\"mce_inlinepopups_50_ifr\"]")));
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[#id=\"imgmanager.insert\"]/i[#class=\"icon-file\"]"))).click();
driver.quit();
}
}
Error:
Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for frame to be available: By.xpath: //iframe[#id="mce_inlinepopups_50_ifr"] (tried for 20 second(s) with 500 milliseconds interval)
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:81)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:271)
at testScripts.Iframe.main(Iframe.java:51)
Caused by: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.xpath: //iframe[#id="mce_inlinepopups_50_ifr"]
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:08.936Z'
System info: host: 'vowellt4', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.15.0-24-generic', java.version: '1.8.0_171'
Driver info: driver.version: unknown
at org.openqa.selenium.support.ui.ExpectedConditions.lambda$findElement$0(ExpectedConditions.java:896)
at java.util.Optional.orElseThrow(Optional.java:290)
at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:895)
at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:44)
at org.openqa.selenium.support.ui.ExpectedConditions$17.apply(ExpectedConditions.java:517)
at org.openqa.selenium.support.ui.ExpectedConditions$17.apply(ExpectedConditions.java:513)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:248)
... 1 more
Just after click on help button , you can try with this code :
driver.switchTo().defaultContent();
new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe[src^='/administrator/index.php?option=com_jce&view=help&tmpl=component&lang=en§ion=editor&category=imgmanager&']")));
You are using //iframe[#id=\"mce_inlinepopups_50_ifr\"] this xpath to switch to frame but the problem is the id is getting generated dynamically , so we do not know what will be the id every time we visit the page through automation.
I have simply converted that xpath to a valid and reliable css selector and it is working extremely good at my end.
In case you want to have xpath :
//iframe[contains(#src,'/administrator/index.php?option=com_jce&view=help&tmpl=component&lang=en§ion=editor&category=imgmanager&')]
Hope this will help.
After clicking on the help button, you need to switch to the default content from the parent iframe and then need to navigate to the respective child frame.
Child Frame Xpath needs to be changed as below
Xpath: //*[#class='mceModalContainer']//div[#id='mce_inlinepopups_45_content']//iframe
Modified Working Code:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[#id=\"browser-actions\"]/a[#id=\"help\"]"))).click();
driver.switchTo().defaultContent();
new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//*[#class='mceModalContainer']//div[#id='mce_inlinepopups_45_content']//iframe")));
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[#id='help-menu']//*[#id=\"imgmanager.insert\"]/i[#class=\"icon-file\"]"))).click();
I am trying to run few test on Mobile Emulators (Safari Browser) and stuck at a problem. Where after switching to an Iframe I am not able to do any action.
There is already a closed issue for that, however I didn't find any solution after going though this thread.
https://github.com/appium/appium/issues/5832
Code which is causing issue
public PaymentPage fillCreditCardInformation(String cardNumber, String expiryDate, String cvv, String postal ){
switchToPaymentFrame();
WebElement cardNumberEditbox = driver.findElement(By.name("cardnumber"));
}
private void switchToPaymentFrame() {
WebElement frame = driver.findElement(By.name("__privateStripeFrame3"));
driver.switchTo().frame(frame);
}
Emulator Used: Iphone 6s, IPad Mini
Webdriver Version: 3.4.0
Safari Driver: 2.48
Stacktrace:
org.openqa.selenium.WebDriverException: undefined is not an object
(evaluating 'a.querySelectorAll') (WARNING: The server did not provide
any stacktrace information) Command duration or timeout: 30.48 seconds
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'DL0019', ip: '127.0.1.1', os.name: 'Linux',
os.arch: 'amd64', os.version: '4.4.0-96-generic', java.version:
'1.8.0_131' Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{noReset=true, safari=true,
browserstack.tunnelIdentifier=, browserstack.asyncStop=true,
language=Apache-HttpClient/4.5.3 (Java/1.8.0_131),
browserstack.selenium_version=3.4.0, deviceName==iPad Retina (9.1)
[556DF534-C4AE-48B6-8ED3-BAF86198074A], platform=MAC,
browserstack.video.disableWaterMark=true, desired={noReset=true,
browserstack.tunnelIdentifier=, browserstack.asyncStop=true,
language=Apache-HttpClient/4.5.3 (Java/1.8.0_131),
browserstack.selenium_version=3.4.0, deviceName==iPad Retina (9.1)
[556DF534-C4AE-48B6-8ED3-BAF86198074A], platform=MAC,
browserstack.video.disableWaterMark=true, acceptSslCerts=false,
newCommandTimeout=300.0, browser=ipad, platformVersion=9.1,
acceptSslCert=false, browserName=safari, platformName=iOS,
64bit=false, browserstack.debug=true, orientation=portrait,
browserstack.ie.noFlash=false, os_version=,
mobile={"browser":"tablet","version":"iPad Mini 4-9.1"},
browserstack.geckodriver=0.16.0, version=, browserstack.video=true,
safariIgnoreFraudWarning=true, orig_os=macelc, realMobile=false,
deviceOrientation=PORTRAIT, device=iPad Retina, proxy_type=node},
acceptSslCerts=false, newCommandTimeout=300.0, browser=ipad,
platformVersion=9.1, webStorageEnabled=false, acceptSslCert=false,
browserName=safari, takesScreenshot=true, javascriptEnabled=true,
platformName=iOS, 64bit=false, browserstack.debug=true,
networkConnectionEnabled=false, orientation=portrait,
browserstack.ie.noFlash=false, warnings={}, os_version=,
mobile={"browser":"tablet","version":"iPad Mini 4-9.1"},
browserstack.geckodriver=0.16.0, databaseEnabled=false, version=,
browserstack.video=true, safariIgnoreFraudWarning=true,
orig_os=macelc, realMobile=false, locationContextEnabled=false,
deviceOrientation=PORTRAIT, device=iPad Retina, proxy_type=node}]
Session ID: 6bf643515813d0ccbe5fe75300ac2d8ea15a5960
*** Element info: {Using=name, value=cardnumber}
Can you try this:
Change:
private void switchToPaymentFrame() {
WebElement frame = driver.findElement(By.name("__privateStripeFrame3"));
driver.switchTo().frame(frame);
}
To:
private void switchToPaymentFrame() {
WebDriverWait wait1 = new WebDriverWait(driver, 10);
wait1.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.name("__privateStripeFrame3")));
}
Seems to me like a known issue.
Simply doesn't work.
https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/7658
I am currently using Java webdriver 2.53.1 for firefox version 2.46.0. I am getting this below error when run my script for a long time. Since I have different profiles to run multiple scripts at a time using same browser. this firefox browser seems getting crashed.
Please find below error details
org.openqa.selenium.UnhandledAlertException: Modal dialog present: A script on this page may be busy, or it may have stopped responding. You can stop the script now, open the script in the debugger, or let the script continue.
Script: https://website/js/jq…596b2b8fa35fe3a634ea342d7c3.js:1
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'MACHINE NAME', ip: 'Ip address', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=47.0.2, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 39cfd1aa-1d74-4b18-bdcd-5255a2b90127
at sun.reflect.GeneratedConstructorAccessor51.newInstance(Unknown Source)
Also I have applied two solutions
say
1.
DesiredCapabilities capabilites = new DesiredCapabilities();
capabilites.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,UnexpectedAlertBehaviour.ACCEPT);
driver = new FirefoxDriver(capabilites);
as per the below link
https://www.google.com.au/url?sa=t&rct=j&q=&esrc=s&source=web&cd=6&cad=rja&uact=8&ved=0ahUKEwjf4_vy-9rUAhXEEbwKHY8_CTUQFghBMAU&url=https%3A%2F%2Fsupport.mozilla.org%2Fen-US%2Fkb%2Fwarning-unresponsive-script&usg=AFQjCNGh0FhTTjSvFduBRRe36UJCGXz8qA
But still the issues seems not fixed on mt script.
Could anyone provide a solution for this?
This error from my experience is only thrown when you are trying to do a page navigation but have not handled an on screen alert. You need to user the IAlert class to accept or dismiss this alert to continue.
First find what command is triggering the alert, then handle the alert.
If you elaborate more on your issue I may be able to help more, it would be helpful if you included the selenium code that is causing this exception.
Here are some functions I use to deal with alerts.
public void AcceptAlert()
{
try
{
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));
wait.Until(ExpectedConditions.AlertIsPresent());
IAlert alert = Driver.SwitchTo().Alert();
alert.Accept();
}
catch (Exception)
{ }
}
public void DismissAlert()
{
try
{
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));
wait.Until(ExpectedConditions.AlertIsPresent());
IAlert alert = Driver.SwitchTo().Alert();
alert.Dismiss();
}
catch (Exception ex)
{
log.Debug(ex.Message);
}
}
The scenario here is that certain pages I'm testing will have an unload event - i.e. prompt to save changes if there are unsaved changes is a common example and I want to be able to detect that and handle it.
Here is the specific problem:
I'm testing a pretty complicated web app which will allow users to edit rich content in a browser and the app will auto-save changes from the user. So this test does something like the following:
Navigate to the app
Do some edits
Navigate away
However, since the app auto-saves changes on navigating away and there are unsaved changes - this prompt will show up: http://i.stack.imgur.com/c9iP2.png
Whenever there is an alert in Selenium, the next action will fail miserably with a callstack like:
org.openqa.selenium.UnhandledAlertException: unexpected alert open
(Session info: chrome=39.0.2171.65)
(Driver info: chromedriver=2.11.298604 (75ea2fdb5c87f133a8e1b8da16f6091fb7d5321e),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 87 milliseconds: null
Build info: version: '2.43.1', revision: '5163bceef1bc36d43f3dc0b83c88998168a363a0', time: '2014-09-10 09:43:55'
System info: host: 'ip-10-231-174-40', ip: '10.231.174.40', os.name: 'Linux', os.arch: 'amd64', os.version: '3.11.0-19-generic', java.version: '1.7.0_51'
Session ID: 889cbda1d1a946a38e90e4ec9f32e827
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, hasMetadata=true, browserName=chrome, chrome={userDataDir=C:\Users\ADMINI~1\AppData\Local\Temp\scoped_dir1584_15883}, rotatable=false, mobileEmulationEnabled=false, locationContextEnabled=true, webdriver.remote.sessionid=889cbda1d1a946a38e90e4ec9f32e827, version=39.0.2171.65, takesHeapSnapshot=true, databaseEnabled=false, cssSelectorsEnabled=true, handlesAlerts=true, browserConnectionEnabled=false, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=false, takesScreenshot=true}]
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:162)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:614)
at org.openqa.selenium.remote.RemoteWebDriver.getCurrentUrl(RemoteWebDriver.java:319)
So one solution might be that I put try/catches whenever my test navigates away from this page but I'm wondering if there is a more elegant and systematic solution (i.e. something that would either detect alerts or page navigation so they get handled).
Does anyone have a working solution for this problem?
You need to switch to alert and accept it. Example in Java:
Alert alert = driver.switchTo().alert();
alert.accept();
You may also need to wait for it to appear before switching:
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.accept();
Alternatively, you can stop the popup to be shown in the first place. The idea is to remove all beforeunload event listeners with javascript:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(
"window.addEventListener(\"load\", foo, false);" +
"function foo() { " +
"var u = \"beforeunload\";" +
"var v = unsafeWindow;" +
"if (v._eventTypes && v._eventTypes[u]) {" +
"var r=v._eventTypes[u];" +
"for(var s=0;s<r.length;s++) { " +
"v.removeEventListener(u,r[s],false);" +
"}" +
"v._eventTypes[u]=[];" +
"}");
I'm using Selenium 2.2.
I am trying to click on elements which are not displayed at first, but become visible
during the test. At first sometimes the webdriver seemed to work too fast so the Elements were not visible in time resulting in ElementNotVisibleExceptions. I added WebDriverWait to wait for these elements to become visible/clickable. But now I'm getting this random error when using
WebDriverWait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id")));
same for
WebDriverWait.until(ExpectedConditions.elementToBeClickable(By.id("id")));
here is the stacktrace
org.openqa.selenium.WebDriverException: Error determining if element is displayed (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 219 milliseconds
Build info: version: '2.20.0', revision: '16008', time: '2012-02-27 19:03:59'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1 build 2600 Service Pack 3', java.version: '1.6.0'
Driver info: driver.version: RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:44)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:516)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:170)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:123)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:438)
at org.openqa.selenium.remote.RemoteWebElement.isDisplayed(RemoteWebElement.java:280)
at org.openqa.selenium.support.ui.ExpectedConditions.elementIfVisible(ExpectedConditions.java:136)
at org.openqa.selenium.support.ui.ExpectedConditions.access$1(ExpectedConditions.java:135)
at org.openqa.selenium.support.ui.ExpectedConditions$4.apply(ExpectedConditions.java:106)
at org.openqa.selenium.support.ui.ExpectedConditions$4.apply(ExpectedConditions.java:1)
at org.openqa.selenium.support.ui.ExpectedConditions$11.apply(ExpectedConditions.java:252)
at org.openqa.selenium.support.ui.ExpectedConditions$11.apply(ExpectedConditions.java:1)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:201)
at MyTest.myTest(MyTest.java:xx)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:600)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
This only happens sometimes. Ignoring the WebDriverException might solve this problem, but that doesn't seem like a clean solution. It can't be a timeout issue because i tried setting my timeout limit to a minute and more and it still fails after a couple of milliseconds.
Anybody got a clean solution to that?
Thanks in advance
Edit: btw. I'm using the InternetExplorerDriver
Make sure page has only one modalPanel. Try get visible panel (java):
public WebElement getVisibleModalPanel(){
for (WebElement element : driver.findElements(By.cssSelector('csslocator'))) {
if (element.isDisplayed()) {
return element;
}
}
return null;
}
Implement wait for such thing:
(new WebDriverWait(getDriver(), timeout, 400)).ignoring(StaleElementReferenceException.class).until(
new ExpectedCondition<Boolean>() {
#Override
public Boolean apply(WebDriver driver) {
for (WebElement element : driver.findElements(By.cssSelector(locator))) {
if (element.isDisplayed()) {
return true;
}
}
return false;
}
});