javascript - Selenium 处理 HTML 弹出窗口

标签 javascript html selenium popup popupwindow

<iframe src="https://authedmine.com/authenticate.html?key=tqao2dYaXfMVJuUNUIwh6OBUUGSW3omn&amp;domain=mining.freebitco.in&amp;theme=light&amp;lang=auto" style="border: none; width: 380px; height: 412px; max-width: 100%; max-height: 100%; position: absolute; overflow: auto; left: 0px; right: 0px; top: 0px; bottom: 0px; margin: auto;"></iframe> 


<body class="light">
<div id="content" style="display: block;">
<a id="set-english-locale" href="#" style="display: block;">English</a>
<h1 id="head">xx</h1>
<p id="body">yy.</p>
<p class="warn" id="batteryWarning">Not:cc.</p>

<div class="actions">
    <button class="allow" id="accept">Bu oturum için izin ver</button> --Need click this--
    <button class="cancel" id="cancel">İptal</button>
</div>

<p class="foot">
    powered by
    <a href="asdadad.com" class="icon">
        coinhive
    </a>
    – 
    <a href="https://coinhive.com/info/opt-in" target="_blank">more info</a>
</p>

我收到了这个错误;

An unhandled exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll Additional information: The HTTP request to the remote WebDriver server for URL http://localhost:57885/session/233d4589882afe49d8dd64d1f9318ac0/element timed out after 60 seconds.

我想点击按钮,但我无法点击。我尝试了很多代码,但我不能:(我停下来等待这段代码。请帮助我。

最后我点击:D 非常感谢@DebanjanB

driver.SwitchTo().Frame(driver.FindElement(By.XPath("/html/body/div[2]/iframe")));
        driver.FindElement(By.XPath("//*[@id='accept']")).Click();
        driver.SwitchTo().DefaultContent();

最佳答案

尝试:

driver.FindElement(By.XPath("//div[@class='actions']/button[@class='allow']").Click();
<小时/>

更新:

正如您所看到的 timeout 异常,检查该元素是否位于 iframe 内。

关于javascript - Selenium 处理 HTML 弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47837616/

相关文章:

javascript - A 型物理动态体无法正常运行

javascript - 在 jquery 移动页面中添加面板会使设备上的页面滚动卡住

java - Selenium 与 Java、Eclipse 和 SmartGWT

python - Selenium 和 phantomjs 不打开 javascript 页面

python - 使用 selenium 从 Highcharts 抓取数据

javascript - setTimeout被连续的AJAX请求阻塞?

javascript - 谷歌地图折线的中间(质心?)

用于非输入标签的 Python Selenium send_keys()

javascript - 使用 javascript/jquery 设置 div 的值/文本 - 在 php 循环内

jquery - DIV 淡入动画