Python Forum

Full Version: Getting error when accessing elements in a modal window of an webpage using selenium
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am writing python code to access elements in a modal dialog box of a webpage. After clicking in a link the modal dialog box appears till this point code works fine but when I am finding elements and trying to access the elements(input button,choosing options from the dropdown menu) in the modal window the error comes.

I have the Image screenshots of the modal window and the code of that but I don't know how to attach those files from my local drive to here.

Below is the code where I am getting the errors.
driver.find_element_by_xpath('//*[@id="form"]/div[5]/button').click()
driver.find_element_by_xpath('/html/body/div[4]/div[2]/div/div[3]/a[4]/div/div[2]/i').click()
try:
    element = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, '//*[@id="myModal"]')))
finally:
    driver.quit()
driver.find_element_by_xpath('//*[@id="myModal"]/div/div/div[3]/button[1]').click()
And this is Error What I am getting.

Error:
File "/home/csurv_4/PycharmProjects/tathya_brityanta/run_a_bot.py", line 34, in <module> element = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, '//*[@id="myModal"]'))) File "/home/csurv_4/PycharmProjects/tathya_brityanta/venv/lib64/python3.6/site-packages/selenium/webdriver/support/wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
Can anyone could suggest me any solution to this?
Well I'm no expert, but it looks like you are trying to locate element By.ID and you are giving it xpath instead?
(Jul-12-2018, 02:04 PM)sumandas89 Wrote: [ -> ]I am writing python code to access elements in a modal dialog box of a webpage. After clicking in a link the modal dialog box appears till this point code works fine but when I am finding elements and trying to access the elements(input button,choosing options from the dropdown menu) in the modal window the error comes.

I have the Image screenshots of the modal window and the code of that but I don't know how to attach those files from my local drive to here.

Below is the code where I am getting the errors.
driver.find_element_by_xpath('//*[@id="form"]/div[5]/button').click()
driver.find_element_by_xpath('/html/body/div[4]/div[2]/div/div[3]/a[4]/div/div[2]/i').click()
try:
    element = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, '//*[@id="myModal"]')))
finally:
    driver.quit()
driver.find_element_by_xpath('//*[@id="myModal"]/div/div/div[3]/button[1]').click()
And this is Error What I am getting.

Error:
File "/home/csurv_4/PycharmProjects/tathya_brityanta/run_a_bot.py", line 34, in <module> element = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, '//*[@id="myModal"]'))) File "/home/csurv_4/PycharmProjects/tathya_brityanta/venv/lib64/python3.6/site-packages/selenium/webdriver/support/wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
Can anyone could suggest me any solution to this?

(Jul-12-2018, 03:30 PM)mlieqo Wrote: [ -> ]Well I'm no expert, but it looks like you are trying to locate element By.ID and you are giving it xpath instead?

I found the mistake that is I should use By.XPATH instead of By.ID. Here I modified the code but still the error comes in the last line due to the access of modal window. Below is the modified code -
try:
    element = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="myModal"]')))
except:
    print("Not able to find Element")
driver.find_element_by_xpath('//*[@id="myModal"]/div/div/div[3]/button[1]').click()
'''Selecting Search By Name'''
driver.find_element_by_xpath('/html/body/div[4]/div[2]/div/div[2]/div[2]/div/ul/li[2]/a').click()
'''Entering The Input Name and Continue Search'''
driver.find_element_by_xpath('//*[@id="d_value"]').send_keys('Suman Das')
After clicking on the modal window it disappears but now I am not able to click on any link or any button in the main webpage. The below error comes -

Error:
File "/home/csurv_4/PycharmProjects/tathya_brityanta/run_a_bot.py", line 39, in <module> driver.find_element_by_xpath('/html/body/div[4]/div[2]/div/div[2]/div[2]/div/ul/li[2]/a').click() File "/home/csurv_4/PycharmProjects/tathya_brityanta/venv/lib64/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click self._execute(Command.CLICK_ELEMENT) File "/home/csurv_4/PycharmProjects/tathya_brityanta/venv/lib64/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 628, in _execute return self._parent.execute(command, params) File "/home/csurv_4/PycharmProjects/tathya_brityanta/venv/lib64/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute self.error_handler.check_response(response) File "/home/csurv_4/PycharmProjects/tathya_brityanta/venv/lib64/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementClickInterceptedException: Message: Element <a href="#portlet_tab2"> is not clickable at point (592.5,216.1999969482422) because another element <div class="modal-backdrop fade"> obscures it
You might want to wait until overlay is closed:
WebDriverWait(driver, 10).until_not(EC.visibility_of_element_located((By.CLASS_NAME, 'modal-backdrop')))