[英]Not able to identify an element in Selenium Webdriver (cookies pop-up on skynews)
I have tried all the methods including xpath but I am still not able to click on the Accept button on cookies popup on https://www.news.sky.com我已经尝试了包括 xpath 在内的所有方法,但我仍然无法点击https://www.news.sky.com上 cookie 弹出窗口上的接受按钮
Tried css selector, xpath, frame etc everything.尝试了 css 选择器、xpath、frame 等一切。
Here is my code:这是我的代码:
public class Browser {公共类浏览器{
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();
}
}
Please can someone help me on this?请问有人可以帮我吗?
I have already gone through a lot of posts on this and other forums but couldn't find an solution.我已经在这个论坛和其他论坛上浏览了很多帖子,但找不到解决方案。
Thanks谢谢
I would suggest the xpath of //button[@title='Accept']
for what it's worth.我会建议
//button[@title='Accept']
的 xpath 的价值。
It's possible the switch to doesn't work because the element doesn't exist yet in the frame.切换到 可能不起作用,因为该元素尚不存在于框架中。
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.