[英]Not able to identify an element in Selenium Webdriver (cookies pop-up on skynews)
我已經嘗試了包括 xpath 在內的所有方法,但我仍然無法點擊https://www.news.sky.com上 cookie 彈出窗口上的接受按鈕
嘗試了 css 選擇器、xpath、frame 等一切。
這是我的代碼:
公共類瀏覽器{
WebDriver driver;
public void browser_open() {
String projectPath = System.getProperty("user.dir");
System.setProperty("webdriver.chrome.driver", projectPath+"\\Drivers\\chromedriver\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
}
public void navigate() throws InterruptedException {
driver.get("http://news.sky.com");
//Thread.sleep(5000);
driver.switchTo().frame("sp_message_iframe_368417");
driver.findElement(By.xpath("/html/body/div/div[3]/div[3]/button[1]")).click();
}
}
請問有人可以幫我嗎?
我已經在這個論壇和其他論壇上瀏覽了很多帖子,但找不到解決方案。
謝謝
我會建議//button[@title='Accept']
的 xpath 的價值。
切換到 可能不起作用,因為該元素尚不存在於框架中。
driver.switchTo().frame("sp_message_iframe_368417");
WebDriverWait wait = new WebDriverWait(driver, 10000);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[@title='Accept']")));
driver.findElement(By.xpath("//button[@title='Accept']")).click();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.