问题
I need to open the search windows on this page.
https://permits.losgatosca.gov/CitizenAccess/default.aspx
With firefox is working just fine, but when I try to do the same with phantomJS i got an error.
This is the code I'm using to open the search
BUTTON_id = 'ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl00_LinkItemUrl' #'//*[@id="ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl00_LinkItemUrl"]/span'
driver_1.switch_to_frame("ACAFrame")
button = driver_1.find_element_by_id(BUTTON_id)
button.click()
And this is the error I'm getting with phanthomJS:
Message: Error Message => 'Unable to switch to frame'
In this post it says that using:
driver.switchTo().frame(frame_index)
driver.switchTo().frame(frame_id)
driver.switchTo().frame(frame_object)
It solves the issue, but I don't know what to put in:
frame_index
frame_id
frame_object
回答1:
This is what you should try:
- upgrade both
selenium
andPhantomJS
to the latest versions add a wait before switching to frame:
from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC wait = WebDriverWait(driver, 10) wait.until(EC.presence_of_element_located((By.ID, "ACAFrame"))) driver.switch_to.frame("ACAFrame")
(worked for me)
来源:https://stackoverflow.com/questions/38207202/switch-frames-with-selenium-and-phantomjs