Geckodriver不能点击元素| python 3编码

2024-06-16 09:19:47 发布

您现在位置:Python中文网/ 问答频道 /正文

正如在主题中所说的,我试图单击一个找到的元素,但是根据geckodriver和firefox(对于Linux)的版本,我得到了两个结果。对于旧版本(如FF38+geckodriver 0.15->;0.17.0),我有一些类似于reportedhere。你知道吗

单击元素时,会出现新窗口,但操作不会终止。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))

显示第一次打印,但不显示第二次打印。如果我使用焦点,结果是一样的_点击(). 你知道吗

更好的应该是使用55+版本,有无头选项。 有解决方法吗?你知道吗


Tags: gt版本browser元素targettitleactionelement
1条回答
网友
1楼 · 发布于 2024-06-16 09:19:47

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

相关问题 更多 >