Geckodriver 无法点击元素 | python3 编码

Geckodriver can't click on element | python 3 Coding

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

元素被点击,新的window出现,但动作并未终止。 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))

显示第 1 个打印,但不显示第 2 个。如果我使用 focus_lnk.click().

结果是一样的

最好使用55+版本,有headless选项。 有这方面的工作吗around/solution?

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');");
                    }
                    """)