最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

org.openqa.selenium.ElementClickInterceptedException: element click intercepted exception using Selenium and Java - Stack Overfl

programmeradmin4浏览0评论

When loading "; i want to decline all the cookies by clicking the button "Decline All". The button is easy to identify and to avoid to click it while it might not be ready or in a non complete state, i use the explicit waiting mecanism of Selenium. Nevertheless i'm getting an 'ElementClickInterceptedException' both with Chrome and Firefox drivers.

Here my source code:

public static void main(String[] args) throws InterruptedException {
        
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--start-maximized");
    options.addArguments("--incognito");
    options.setImplicitWaitTimeout(Duration.ofSeconds(5L));     

    WebDriver driver = new ChromeDriver(options);
        
    driver.get(";);

    WebDriverWait waitManager = new WebDriverWait(driver, Duration.ofSeconds(5L));
    WebElement btnDecline = waitManager.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@id='gdpr-banner-decline']")));
    System.out.println(btnDecline.getText());
//  Thread.sleep(Duration.ofSeconds(3L));
    btnDecline.click();

The console prints as expected "Decline All" but the following click() statement throws the Exception.

I tried to check this behaviour in another browser (Firefox) but still i got the same Exception, the button is not clickable. However when i inserted before clicking a sleep statement, it works fine and no Exception is thrown. I'm looking for a genuine solution of this issue.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论