Make sure to import org.openqa.selenium.JavascriptExecutor;
\JavascriptExecutor js = (JavascriptExecutor)driver;
// if the element is on top. js.executeScript("scroll(250, 0)"); // if the element is on bottom. js.executeScript("scroll(0, 250)");
\JavascriptExecutor js = (JavascriptExecutor)driver;
// if the element is on top. js.executeScript("scroll(250, 0)"); // if the element is on bottom. js.executeScript("scroll(0, 250)");
WebElement element = driver.findElement(By.id(""));
JavascriptExecutor js =(JavascriptExecutor)driver;
js.executeScript("window.scrollTo(0,"element.getLocation().y+")");
element.click();
You can also try the below using X or Y position
WebElement element = driver.findElement(By.id(""));
JavascriptExecutor js =(JavascriptExecutor)driver;
js.executeScript("window.scrollTo(0,"element.getLocation().y+")");
element.click();
Thank you for this valuable information,enjoy blogging!
ReplyDeleteselenium Training
selenium Online Training
selenium Training in Hyderabad
nice post.Thank you for sharing this postSelenium training in chennai | Selenium training in velachery
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteGreat tip! Importing org.openqa.selenium.JavascriptExecutor is essential when you need to execute JavaScript directly in Selenium WebDriver. It really helps in handling elements that aren’t easily accessible via standard locators and improves test automation efficiency. online IT courses with certification
ReplyDelete