gpt4 book ai didi

python - Geckodriver 无法点击元素 | python 3 编码

转载 作者:行者123 更新时间:2023-12-01 09:18:56 25 4
gpt4 key购买 nike

正如主题中所述,我尝试单击找到的元素,但根据 geckodriver 和 firefox(适用于 Linux)版本,我得到 2 个结果。对于旧版本(例如 FF38 + geckodriver 0.15 -> 0.17.0),我有类似报告 here 的内容.

单击该元素,出现新窗口,但操作并未终止。 Geckodriver 挂起点击。

对于较新的版本(FF52 ESR -> FF60 ESR + geckodriver 0.19.0 -> 0.21.0),单击没有效果...当然我不能使用 send_keys() 方法。

这是元素:

<span onclick="modalClientPopup('http://myserver.local/target', null, 800, null, false);">
<img src="img/target.gif" title="Target" alt="Target" onmouseover="iconOnmouseover(this, 0);" onmouseout="iconOnmouseout(this, 0);">
<br>
<label id="home_label_0" title="Target" style="text-decoration: underline; cursor: auto; font-weight: normal;" onmouseover="iconOnmouseover(this, 0);" onmouseout="iconOnmouseout(this, 0);">
Target folder
</label>
</span>

这是代码:

iframe = browser.find_element_by_xpath("//iframe[@keyid='1/ACCUEIL']")
browser.switch_to.frame(iframe)
focus_lnk = browser.find_element_by_xpath("//label[@title='Target']")
window = browser.window_handles
print(len(window))
action = ActionChains(browser)
action.move_to_element(focus_lnk)
action.click(focus_lnk)
action.perform()
print(len(window))

显示第一个打印,但不显示第二个。如果我使用 focus_lnk.click(),结果是相同的。

更好的应该是使用 55+ 版本,以获得 headless 选项。有解决办法吗?

最佳答案

modalClientPopup() 引用了 window.showModalDialog(),但已弃用。

所以我用一段 JavaScript 即时更改了 html 代码:

browser.execute_script("""
setInterval (function() { override (); }, 500);

function override () {
var divElem;
var innerDoc;
var focus;
divElem = document.getElementsByClassName('content_sub_zone');
innerDoc = divElem[0].childNodes[0].contentDocument;
focus = innerDoc.getElementsByTagName('span')[0];
focus.setAttribute("onclick", "window.open('http://myserver.local/target', '', 'width=800,height=400');");
}
""")

关于python - Geckodriver 无法点击元素 | python 3 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50971533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com