Reputation: 135
I'm trying to automate a daily task, but I got stuck with some nested iframes. The script is working very well till the part of unselecting all document types, it fails.
I tried waiting until the element is clickable. Also, I tried accessing the element with id, css_selector and XPath but nothing helped.
I think the element is located within nested iframes, but can't get the correct sequence.
Here's my script:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
options = webdriver.ChromeOptions()
options.add_argument("disable-infobars")
#options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument('--disable-dev-shm-usage')
#options.add_argument('--disable-gpu')
options.add_argument("--start-maximized")
options.add_experimental_option("excludeSwitches",["ignore-certificate-errors"])
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
link = r"https://countyfusion10.kofiletech.us/countyweb/loginDisplay.action?countyname=TylerWV"
options.add_experimental_option("prefs", {
"download.directory_upgrade":True,
"safebrowsing.enabled":True,
"download.prompt_for_download":False,
"plugins.always_open_pdf_externally": True,
})
driver = webdriver.Chrome(executable_path='./chromedriver', options=options)
driver.get(link)
#Login as Guest
driver.find_element_by_xpath(r'//*[@id="maindiv"]/table[2]/tbody/tr[1]/td[2]/table/tbody/tr/td/center/input').click()
time.sleep(5)
#Accept Disclaimer
driver.switch_to.frame("bodyframe")
driver.find_element_by_id(r'accept').click()
time.sleep(30)
#Deselect All types
driver.switch_to.default_content()
boxes = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,r'//*[@id="elemAllNamesJSP_20"]/table/tbody/tr/td[2]/span/input[1]')))
print(boxes)
Upvotes: 0
Views: 410
Reputation: 33361
I'm not sure you had to switch to the default content, anyway since you got out of the bodyframe
iframe to access the "boxes" element you have switch to the first parent iframe first, then to the inner parent and then to the inner child. Like this:
driver = webdriver.Chrome(executable_path='./chromedriver', options=options)
driver.get(link)
#Login as Guest
driver.find_element_by_xpath(r'//*[@id="maindiv"]/table[2]/tbody/tr[1]/td[2]/table/tbody/tr/td/center/input').click()
#Accept Disclaimer
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it(By.NAME,"bodyframe"))
driver.find_element_by_id(r'accept').click()
#Deselect All types
driver.switch_to.default_content()
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it(By.NAME,"bodyframe"))
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it(By.NAME,"dynSearchFrame"))
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it(By.NAME,"criteriaframe"))
boxes = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,r'//*[@id="elemAllNamesJSP_20"]/table/tbody/tr/td[2]/span/input[1]')))
print(boxes)
I'm not sure what you trying to achieve by printing the web element "boxes" with print(boxes)
...
Also I removed the hardcoded delays. Especially the 30 seconds sleep, you don't need it. Use webdriver explicit wait instead.
It will work much faster and still stable.
Upvotes: 1