Switch frames with selenium and phantomJS

前提是你 提交于 2019-12-23 04:09:16

问题


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 and PhantomJS 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!