【问题标题】:press ESC without selection a element selenium java按 ESC 而不选择元素 selenium java
【发布时间】:2020-11-21 23:56:19
【问题描述】:

我正在尝试进入硒。如果我尝试访问www.snipes.com 网站,则会弹出一个区域选择弹出窗口。我找不到关闭它的元素,但如果我按 ESC,这个弹出窗口会自行关闭。有没有办法在不先选择元素的情况下按 ESC 键?如果不是,“x”的类名是什么,或者我可以用什么元素用 ESC 键关闭它?

//to close the pop up with the "x"
  ChromeDriver driver = new ChromeDriver();
            
        
            //Snipes Region
            driver.get("https://www.snipes.com/login");
            TimeUnit.SECONDS.sleep(2);
            selectRegion = driver.findElementByClassName("js-close-btn a-modal-close-button close");
            selectRegion.click();
            

html code, cant find the className

the pop up im trying to get rid of

【问题讨论】:

    标签: java selenium popup element


    【解决方案1】:

    你可以使用下面的xpath来点击关闭按钮:

    "//*[@class='i-close-thin']"
    

    你也可以向 body 元素发送转义

    driver.findElement(By.xpath("//body")).sendKeys(Keys.ESCAPE)
    

    【讨论】:

    • 谢谢,但现在我不得不提出问题,有时可以找到元素,但大多数时候找不到。没有元素就不能发送 Key ESCAPE 吗?
    • 只需添加显式等待正文可用
    猜你喜欢
    • 1970-01-01
    • 2018-02-09
    • 1970-01-01
    • 2023-03-16
    • 2021-12-23
    • 1970-01-01
    • 2015-04-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多