2

the function:

def twoclicks(idoutter,idinner):
    wait = WebDriverWait(driver, 20)
    wait.until(EC.element_to_be_clickable((By.XPATH, "//input[contains(@id," + idoutter + ") and @value='...']"))).click()
    sleep(5)
    wait.until(EC.element_to_be_clickable((By.ID, idinner))).click()

This function is used to click an element then have a pop up a few seconds later and click an element of the popup.

I keep getting that error although i tried adding sleep() in my function and it's inconsistent as in i get it at times and i don't at others.

My previous function was:

def twoclicks(idoutter,idinner):
    outter = driver.find_element_by_xpath("//input[contains(@id," + idoutter + ") and @value='...']")
    outter.click()
    sleep(10)
    driver.find_element_by_id(idinner).click()
     sleep(7)

although my second function is a bad practice and the first one is supposed to be an improvement but i didn't get that exception using my second one.How can i adjust my first shared function to get rid of that error.

kindly note the code is a continuous call for similar functions like :

twoclicks("'button1'", 'button2')
twoclicks("'button3'", 'button4')

The div obscurint it is :

<div class="rich-mpnl-mask-div-opaque rich-mpnl-mask-div" id="PWBFormID:managerModalPanelDiv" style="z-index: -1;"><button class="rich-mpnl-button" id="PWBFormID:managerModalPanelFirstHref"></button></div>

it's in grey in the html(when inspecting).

I saw many methods like using execute_script() to block the div with the shared class above but the issue is i'm using a function for it and have dozens of buttons that won't have that issue or potentially have it with a different class which is making getting rid of such cases without manually writing a code for them alone case by case outside my twoclicks() function very difficult.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Steve
  • 55
  • 1
  • 5
  • Does this [discussion](https://stackoverflow.com/questions/44912203/selenium-web-driver-java-element-is-not-clickable-at-point-36-72-other-el/44916498#44916498) helps you? – undetected Selenium Feb 11 '19 at 20:34
  • @DebanjanB i have seen that answer yet found nothing in it that would explain why my initial function worked fine but the "improved" version is throwing that exception specially that i'm new. – Steve Feb 11 '19 at 20:38
  • Umm, I still don't see you handling the `pop up` properly. Do you need to click within the `pop up` for it to disappear or it vanishes itself? Possibly `pop up` causing you the issue – undetected Selenium Feb 11 '19 at 20:43
  • A new window pops up where i have to click on some element on it. – Steve Feb 12 '19 at 06:45

1 Answers1

0

You can try to wait until Javascript to completed. Try wait method below:

def waitforload():
    wait.until(lambda d: d.execute_script(
        'return (document.readyState == "complete" || document.readyState == "interactive")'))


def twoclicks(idoutter, idinner):
    wait.until(EC.element_to_be_clickable((By.XPATH, "//input[contains(@id," + idoutter + ") and @value='...']"))).click()
    waitforload()
    wait.until(EC.element_to_be_clickable((By.ID, idinner))).click()
    waitforload()
Sers
  • 12,047
  • 2
  • 12
  • 31