Python Forum
Getting error when accessing elements in a modal window of an webpage using selenium
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting error when accessing elements in a modal window of an webpage using selenium
#1
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?
Reply
#2
Well I'm no expert, but it looks like you are trying to locate element By.ID and you are giving it xpath instead?
Reply
#3
(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
Reply
#4
You might want to wait until overlay is closed:
WebDriverWait(driver, 10).until_not(EC.visibility_of_element_located((By.CLASS_NAME, 'modal-backdrop')))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error 404 when loading my webpage dissi 0 116 Mar-20-2024, 03:12 PM
Last Post: dissi
  Selenium Window Not Closing gw1500se 4 2,520 May-02-2022, 02:23 PM
Last Post: gw1500se
  Locating elements via Selenium peterjv26 2 2,432 Oct-02-2020, 07:50 AM
Last Post: peterjv26
  Selenium: accessing a drop-down menus without select tags ClassicalSoul 0 2,029 Apr-19-2020, 03:53 PM
Last Post: ClassicalSoul
  Selenium cant get elements from HTML(Rookie) Troop 1 2,129 Mar-31-2020, 03:37 AM
Last Post: Larz60+
  Selenium Random Elements Id and class AgileAVS 1 3,667 Mar-01-2020, 12:31 PM
Last Post: metulburr
  Selenium weird error julio2000 0 1,646 Feb-23-2020, 01:24 PM
Last Post: julio2000
  Selenium webdriver error WiPi 4 11,977 Feb-09-2020, 11:38 AM
Last Post: WiPi
  error when running headless selenium julio2000 2 4,503 Feb-01-2020, 12:41 PM
Last Post: julio2000
  Error clicking button with selenium julio2000 4 5,246 Jan-06-2020, 10:59 AM
Last Post: julio2000

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020