Hi I am facing an error which is mentioned below. I am unable to click on the button of Buyer as mentioned in the screenshot. I have tried wait, sleep functions too. But unable to move beyond this. Can anyone help me in it.
Can anyone please help me in this: Inspect Element code is .
Code is:
driver.findElement(By.name("login")).click(); //Click on login button
System.out.println("hello world-----4");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("hello world-----5");
WebElement element = driver.findElement(By.xpath("//*
[@id=\"modeuser\"]/div/ul/li[3]"));
((JavascriptExecutor)
driver).executeScript("arguments[0].scrollIntoView(true);", element);
element.click();
//Click on usertype
Error:
Exception in thread "main"
org.openqa.selenium.ElementNotInteractableException: Element <li
class="buyer_border changeusermode "> could not be scrolled into view
Build info: version: '3.9.0', revision: '698b3178f0', time: '2018-02-
05T14:56:13.134Z'
System info: host: 'CLAVAX-PC-93', ip: '192.168.2.122', os.name: 'Windows
10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox,
browserVersion: 58.0.2, javascriptEnabled: true, moz:accessibilityChecks:
false, moz:headless: false, moz:processID: 14260, moz:profile:
C:\Users\Rahul\AppData\Loca..., moz:webdriverClick: true, pageLoadStrategy:
normal, platform: XP, platformName: XP, platformVersion: 10.0, rotatable:
false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
HTML is :
<div class="right hide-on-med-and-down head_right_mar" id="modeuser">
<!-- <div class="toggleWrapper">
<input class="dn" type="checkbox" id="dn" value="1"/>
<label class="toggle" for="dn"><span class="toggle__handler"></span></label>
</div> -->
<div class="right_toggle">
<ul>
<li data-get="seller" class="changeusermode active">
<span>Seller</span>
<span class="nav_span">On</span>
</li>
<li class="mid_toggle">
<div class="switch">
<label>
<input class="changeusermode_btn" type="checkbox" data-on="Yes" data-off="No">
<span class="lever"></span>
</label>
</div>
</li>
<li data-get="buyer" class="buyer_border changeusermode ">
<span>Buyer</span>
<span class="nav_span">Off</span>
</li>
</ul>
</div>
</div>
Selenium can execute commands in Javascript with the help of the execute_script() method. For the Javascript solution, we have to pass true value to the method scrollIntoView() to identify the object below our current location on the page. We can execute mouse movement with the help of the Actions class in Selenium.
Class ElementNotInteractableExceptionThrown to indicate that although a WebElement is present on the DOM, it is not in a state that can be interacted with. This includes an element that is not displayed or whose center point can not be scrolled into the viewport. See Also: Serialized Form.
First of all, verify that the element is in your frame.
If it's not, you will need to switch to the correct frame in order to click on the element:
driver.switchTo().frame(driver.findElement(By.name("iframeWithElement")));
In addition, there is a number of steps you can do in order to improve the stability while clicking on different UI elements:
Does it help the stability?
WebDriverWait wait = new WebDriverWait(driver, 3);
JavascriptExecutor js = ((JavascriptExecutor) driver);
//presence in DOM
wait.until(ExpectedConditions.presenceOfElement(By.id("ID")));
//scrolling
WebElement element = driver.findElement(By.id("ID")));
js.executeScript("arguments[0].scrollIntoView(true);", element);
//clickable
wait.until(ExpectedConditions.elementToBeClickable(By.id("ID")));
So for example, if I'm working on the site, I will use:
Wait.until(ExpectedConditions.presenceOfElement(By.class("article-feed-title")));
Could be caused by this existing bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1422272
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With