I need to click on a button 'NEW'. The element button is visible on DOM but it's not clickable because it's overlapped and i need to scroll down left side of the page to make it clickable. I was trying inject some javascript but it didn't help in my case:
JavascriptExecutor js = ((JavascriptExecutor) driver);
js.executeScript("scroll(" + driver.findElement(By.xpath(//div[@class = 'save-new'])).getLocation().getX() + "," + driver.findElement(By.xpath(//div[@class = 'save-new'])).getLocation().getY() + ")");
Try:
targetElement = driver.findElement(By.xpath("your xpath"));
JavascriptExecutor js = ((JavascriptExecutor) driver);
// This:
js.executeScript("arguments[0].scrollIntoView(true);", targetElement);
targetElement.click();
// Or maybe even just:
js.executeScript("arguments[0].click();", targetElement);
As i feel @damian should worked but you can also tried my code I used it so mny times
Use this code:
WebElement element = driver.findElement(By.xpath("Value"));
((JavascriptExecutor)driver).executeScript(“arguments[0].scrollIntoView();”, element);
element.click();
You can try this way:--
JavascriptExecutor js = ((JavascriptExecutor) driver);
//Scroll your page to down using below code
((JavascriptExecutor)driver).executeScript(“window.scroll(100,2000)”);
// click on button
driver.findElement(By.xpath(//div[@class ='save-new'])).click()
Hope this help you :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.