用硒和幻影切换框架 [英] Switch frames with selenium and phantomJS
本文介绍了用硒和幻影切换框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在此页面上打开搜索窗口。
I need to open the search windows on this page.
https://permits.losgatosca.gov/CitizenAccess/default.aspx
使用firefox工作正常,但是我尝试用phantomJS做同样的错误。
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()
这是我用phanthomJS得到的错误:
And this is the error I'm getting with phanthomJS:
Message: Error Message => 'Unable to switch to frame'
在这个帖子说它使用:
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
推荐答案
这是你应该尝试的:
- 将
selenium
和PhantomJS
升级到最新版本 -
在切换到框架之前添加等待:
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")
(为我工作)
这篇关于用硒和幻影切换框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文