'Getting a NoSuchElementException when trying to find a text box inside a Modal Dialog box while using Python Selenium

I'm trying to input text into a textbox that's part of a popup dialog page, which I think is a modal dialogue box.

After I successfully click on a button on the page with this code:

driver.find_element_by_xpath('//*[@id="get_content"]/div[1]/div/div[2]/h3').click()

I get a dialog box with some textboxes. When I try to input text into one of the textboxes with the following code:

driver.find_element_by_xpath('//*[@id="textbox"]').send_keys("Update Cases")

I get the following error:

NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="textbox"]"}

I tried clicking on the popup dialog box:

driver.find_element_by_xpath('//*[@id="popup_dialog"]').click()

Only to get this error:

ElementNotInteractableException: element not interactable: element has zero size

I tried putting this line before the code above to switch to the active screen:

driver.switch_to.active_element

The line didn't generate any errors. But "method":"xpath","selector":"//*[@id="textbox"]" still yielded NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="textbox"]"}.

I tried: WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="textbox"]'))).send_keys('Update Cases') I got a TimeoutException.

The following is the outer HTML for the popup dialog box.

The page is internal, but the following is partial outer HTML code for the

<div id="popup_dialog"><div class="popup_dialog create_request_dialog"><div class="item_header has_icon"><div class="item_icon"><img src="/servicedesk/customershim/secure/viewavatar?...<div class="popup_dialog_cover"></div></div>

Thus far, none of the above has worked. Any suggestions?



Solution 1:[1]

I see no elements with id="textbox" in HTML you presenting here.
As about the

driver.find_element_by_xpath('//*[@id="popup_dialog"]').click()

Try adding a wait condition there, something like

 WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH,'//*[@id="popup_dialog"]'))).click()

We can only guess about the correct solution here since we can't see and debug the page you are working on

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Prophet