Getting error when accessing elements in a modal window of an webpage using selenium - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Getting error when accessing elements in a modal window of an webpage using selenium (/thread-11506.html) |
Getting error when accessing elements in a modal window of an webpage using selenium - sumandas89 - Jul-12-2018 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. Can anyone could suggest me any solution to this?
RE: Getting error when accessing elements in a modal window of an webpage using selenium - mlieqo - Jul-12-2018 Well I'm no expert, but it looks like you are trying to locate element By.ID and you are giving it xpath instead? RE: Getting error when accessing elements in a modal window of an webpage using selenium - sumandas89 - Jul-13-2018 (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. (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 -
RE: Getting error when accessing elements in a modal window of an webpage using selenium - mlieqo - Jul-13-2018 You might want to wait until overlay is closed: WebDriverWait(driver, 10).until_not(EC.visibility_of_element_located((By.CLASS_NAME, 'modal-backdrop'))) |