I'm writing java selenium. Everything is ok, but when the new tab is opened, the scrool code I added does not open in the new tab? How can I include the codes I wrote in the new tab?
I want the page to go down in the new tab and click on the image I want
CodePudding user response:
This is the code scheme I wrote
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\*\\Desktop\\driver\\chromedriver_win32\\chromedriver.exe");
WebDriver driver;
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.hepsiburada.com/");
Thread.sleep(5000);
driver.findElement(By.xpath("//button[text()='Kabul Et']")).click();
////input[@name='query_text']
driver.findElement(By.xpath("//input[@class='desktopOldAutosuggestTheme-UyU36RyhCTcuRs_sXL9b']")).sendKeys("HBCV00000ODHHV"); ////bu arama çubuğuna yazıyor
Thread.sleep(2000);
driver.findElement(By.xpath("//input[@class='desktopOldAutosuggestTheme-UyU36RyhCTcuRs_sXL9b']")).sendKeys(Keys.ENTER); ////bu tıklattırıyor
Thread.sleep(5000);
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(0, 300);");
Thread.sleep(5000);
driver.findElement(By.xpath("//div[@type='comfort']")).click();
Thread.sleep(5000);
JavascriptExecutor jsx = (JavascriptExecutor)driver;
jsx.executeScript("scroll(0, 300);");
CodePudding user response:
Scrolling to web element:
public static void main(String[] args) {
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.get("https://mrslavchev.com");
JavascriptExecutor js = (JavascriptExecutor) driver;
//This will scroll the page till the element is found
WebElement footer = driver.findElement(By.xpath("//div[@class='site-info-text']"));
js.executeScript("arguments[0].scrollIntoView();", footer);
}