【问题标题】:Selenium Handling a HTML PopupSelenium 处理 HTML 弹出窗口
【发布时间】:2017-12-15 18:01:51
【问题描述】:
<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>

我得到了这个错误;

“OpenQA.Selenium.WebDriverException”类型的未处理异常 发生在 WebDriver.dll 附加信息:HTTP 请求 URL 的远程 WebDriver 服务器 http://localhost:57885/session/233d4589882afe49d8dd64d1f9318ac0/element 60 秒后超时。

我想点击按钮,但我不能点击..我尝试了很多代码,但我不能:(我停止了这个代码。请帮助我。

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

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

【问题讨论】:

  • 你能分享错误跟踪吗?
  • WebDriver.dll 中发生了“OpenQA.Selenium.WebDriverException”类型的未处理异常附加信息:对远程 WebDriver 服务器的 HTTP 请求以获取 URL。我收到此错误

标签: javascript html selenium popup popupwindow


【解决方案1】:

试试:

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

更新:

如您所见,timeout 异常检查元素是否在 iframe 内。

【讨论】:

  • @Oni 你能粘贴更多的outerHTML和完整的错误堆栈跟踪吗?
  • 我添加了新东西
  • @Oni 正如您所尝试的,绝对不是警报。检查它是否在 iFrame 内。
猜你喜欢
  • 2021-01-11
  • 2021-01-11
  • 1970-01-01
  • 1970-01-01
  • 2013-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多