user6838159
user6838159

Reputation:

the OK button can't be click - why?

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

Upvotes: 0

Views: 841

Answers (5)

user6838159
user6838159

Reputation:

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

Upvotes: 0

Danny
Danny

Reputation: 287

"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

Upvotes: 0

Danny
Danny

Reputation: 287

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

Upvotes: 1

Byeongguk Gong
Byeongguk Gong

Reputation: 113

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

Upvotes: 0

Reez0
Reez0

Reputation: 2689

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

Upvotes: 0

Related Questions