0

The below is the id of the "Ok" button inside the popup window , just wanted to say that i was able to sendkeys and ENTER for another field inside the same popup window : OK button

The exception i'm getting is:

selenium.common.exceptions.ElementNotInteractableException: Message: Cannot click on element

Also adding the actual GUI : actual window

The code is below:

def create_new_customer_iden():
    browser.find_element_by_css_selector("#customer_care_app_tab > tbody > tr > td:nth-child(2)").click()
    browser.find_element_by_css_selector("#add_customer > td:nth-child(2)").click()
    browser.find_element_by_id("go_srch_button").click()
    random_number=random.randrange (10000, 99999)
    statement ='INSERT INTO sa_customer(CUSTOMER_NO, CUSTOMER_NAME) VALUES(:1, :2)'
    cursor.execute(statement,(random_number,random_number))
    connection.commit()
    browser.find_element_by_name("popup_search_init_customer_id").send_keys(random_number)
    browser.find_element_by_name("popup_search_init_customer_id").send_keys(Keys.ENTER)
    # works great until here
    browser.find_element_by_id("ok_button").click()

i found another issue : if i'm adding the below lines of code :

button=browser.find_element_by_id ("ok_button")
print(button)
button.click()

The print gives me this element:

selenium.webdriver.remote.webelement.WebElement (session="75fba3d3-bef4-4800-a03d-bfbfcf831209", element="4d27c723-ed64-40a5-9da0-102a52f4d910")

BUT the last line of code throws me the below exception :

selenium.common.exceptions.ElementNotInteractableException: Message: Cannot click on element

WHICH means that i need to find a subtitute to the click() operation. Any suggestions ???

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • You're gonna have to show us the code you already have, and perhaps a link to the page if possible. – Reez0 Nov 27 '17 at 08:45
  • 1
    I edited my question with the added code –  Nov 27 '17 at 08:49
  • 2
    Possible duplicate of [How to resolve ElementNotInteractableException in Selenium webdriver?](https://stackoverflow.com/questions/43868009/how-to-resolve-elementnotinteractableexception-in-selenium-webdriver) – undetected Selenium Nov 27 '17 at 10:48

5 Answers5

1

Try one of the following once the popup loads - driver.switch_to_frame(webelement) / driver.switch_to_window(window_name)

Once you've finished interacting with the popup, e.g. you've closed it use driver.switch_to_default_content() to return to the main page

window_name can be defined by

var window_name = driver.find_element_by_class_name("popup_table")

If none of the above works, the last thing I can suggest to try is: driver.switch_to_alert()

For more information please see: Python webdriver to handle pop up browser windows which is not an alert

Switch to popup in python using selenium

I'd also suggest reading through the Python documentation: http://selenium-python.readthedocs.io/navigating.html - you'll probably find the answer here if the above doesn't help. I'm not really familiar with Python

Danny
  • 287
  • 2
  • 15
  • it's not defined as iframe but as div id –  Nov 27 '17 at 08:54
  • What is the window name according to the DOM I've attached ?- i tried any name there and it didn't work –  Nov 27 '17 at 09:08
  • no still : selenium.common.exceptions.ElementNotInteractableException: Message: Cannot click on element –  Nov 27 '17 at 09:46
  • try read this https://seleniumwithjavapython.wordpress.com/selenium-with-python/switching-between-windows-and-alerts/ and http://selenium-python.readthedocs.io/navigating.html – Danny Nov 27 '17 at 09:54
0

Try this and then see what exception is thrown?

wait = WebDriverWait(driver, 10)
element = wait.until(expected_conditions.element_to_be_clickable((By.ID, "ok_button")))
Reez0
  • 2,512
  • 2
  • 17
  • 39
  • the exception : raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: –  Nov 27 '17 at 09:03
0

How about using XPath or selector? Chrome DevTools provide them.

Here's the sample code

browser.find_element_by_xpath("insert ok_button xpath").click()
browser.find_element_by_css_selector("insert ok_button selector").click()
Byeongguk Gong
  • 113
  • 1
  • 9
0

"The print gives me this element: selenium.webdriver.remote.webelement.WebElement (session="75fba3d3-bef4-4800-a03d-bfbfcf831209", element="4d27c723-ed64-40a5-9da0-102a52f4d910") BUT the last line of code throws me the below exception : selenium.common.exceptions.ElementNotInteractableException: Message: Cannot click on element WHICH means that i need to find a subtitute to the click() operation. Any suggestions ???"

Yes, try the below:

def create_new_customer_iden():
    browser.find_element_by_css_selector("#customer_care_app_tab > tbody > tr > td:nth-child(2)").click()
    browser.find_element_by_css_selector("#add_customer > td:nth-child(2)").click()
    browser.find_element_by_id("go_srch_button").click()
    random_number=random.randrange (10000, 99999)
    statement ='INSERT INTO sa_customer(CUSTOMER_NO, CUSTOMER_NAME) VALUES(:1, :2)'
    cursor.execute(statement,(random_number,random_number))
    connection.commit()
    browser.find_element_by_name("popup_search_init_customer_id").send_keys(random_number)
    browser.find_element_by_name("popup_search_init_customer_id").send_keys(Keys.ENTER)

element = browser.find_element_by_class_name("popup_table")
browser.switch_to_window(window_name)

okButton = browser.find_element_by_id("ok_button")
actions = ActionChains(browser)
actions.move_to_element(okButton).perform()
actions.click(okButton)
//some action to close the popup
browser.switch_to_default_content()

if not, try this...

def create_new_customer_iden():
    browser.find_element_by_css_selector("#customer_care_app_tab > tbody > tr > td:nth-child(2)").click()
    browser.find_element_by_css_selector("#add_customer > td:nth-child(2)").click()
    browser.find_element_by_id("go_srch_button").click()
    random_number=random.randrange (10000, 99999)
    statement ='INSERT INTO sa_customer(CUSTOMER_NO, CUSTOMER_NAME) VALUES(:1, :2)'
    cursor.execute(statement,(random_number,random_number))
    connection.commit()
    browser.find_element_by_name("popup_search_init_customer_id").send_keys(random_number)
    browser.find_element_by_name("popup_search_init_customer_id").send_keys(Keys.ENTER)

driver.switch_to_alert()

okButton = browser.find_element_by_id("ok_button")
actions = ActionChains(browser)
actions.move_to_element(okButton).perform()
actions.click(okButton)
//some action to close the popup
browser.switch_to_default_content()

Obviously you may need to change this slightly to fit in with your code, e.g. browser instead of driver.

https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.action_chains.html

Danny
  • 287
  • 2
  • 15
  • Nothing happens - it is just stuck on the last line of code- the OK button is not clicked and the screen with the popup remains open forever –  Nov 27 '17 at 10:51
  • still nothing happens - just stuck on the popup window and not clickingg –  Nov 27 '17 at 11:43
  • try this first driver.switch_to_alert() – Danny Nov 27 '17 at 11:45
  • Nope, added also that and still freezing –  Nov 27 '17 at 11:49
  • Hmm I'm not too sure then, if you provide the web link for the page then I could possibly have a look – Danny Nov 27 '17 at 12:16
  • Its intranet - can't be entered outside the organization –  Nov 27 '17 at 12:23
  • Okay, well I've updated my answer one last time, if this doesn't work, I'm completely out of ideas... – Danny Nov 27 '17 at 13:04
  • The first solution exception is : urllib.error.URLError: The second solution just made it freeze again. –  Nov 27 '17 at 13:18
  • This is just an Enigma - i will find it out tomorrow with our developers because i really tried any possible solution. thanks anyway. –  Nov 27 '17 at 13:19
0

Ok the issue was solved eventually by me : it appears that there are 2 buttons with the same ID - so i added index as below :

browser.find_element_by_xpath('(//*[@id="ok_button"])[2]').click()

IT WORKED !!!!