Java selenium school代码在新选项卡中不工作



我在写java selenium。一切正常,但是当打开新标签页时,我添加的学校代码没有在新标签页中打开?我如何在新标签中包含我写的代码?

我想让页面在新选项卡中向下点击我想要的图像

这是我编写的代码方案

public static void main(String[] args)抛出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);");

滚动到网页元素:


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);
}

相关内容

  • 没有找到相关文章

最新更新