tealc
tealc

Reputation: 57

Geckodriver can't click on element | python 3 Coding

As said in the subject, I'm trying to click on a found element, but depending on geckodriver and firefox (for Linux) versions, I get 2 results. With old versions (like FF38 + geckodriver 0.15 -> 0.17.0), I have something like reported here.

The element is clicked, the new window appears, but the action is not terminated. Geckodriver hangs the click.

For newer versions (FF52 ESR -> FF60 ESR + geckodriver 0.19.0 -> 0.21.0) the click has no effect... And of course I can't use the send_keys() method.

Here is the element :

<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>

Here is the code :

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))

The 1st print is displayed, but not the 2nd. The result is the same if I use focus_lnk.click().

The better should be to use 55+ versions, to have the headless option. Is there a work around/solution for this?

Upvotes: 1

Views: 139

Answers (1)

tealc
tealc

Reputation: 57

modalClientPopup() is referring to window.showModalDialog(), which is deprecated.

So I have altered the html code on the fly, with a piece of JavaScript :

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

Upvotes: 1

Related Questions