Python 使用selenium和phantomJS切换帧
我需要打开此页面上的搜索窗口 使用firefox很好,但是当我尝试使用phantomJS时,我遇到了一个错误 这是我用来打开搜索的代码Python 使用selenium和phantomJS切换帧,python,selenium,iframe,phantomjs,Python,Selenium,Iframe,Phantomjs,我需要打开此页面上的搜索窗口 使用firefox很好,但是当我尝试使用phantomJS时,我遇到了一个错误 这是我用来打开搜索的代码 BUTTON_id = 'ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl00_LinkItemUrl' #'//*[@id="ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl
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时遇到的错误:
Message: Error Message => 'Unable to switch to frame'
在帖子中说,使用:
driver.switchTo().frame(frame_index)
driver.switchTo().frame(frame_id)
driver.switchTo().frame(frame_object)
它解决了问题,但我不知道该放什么进去:
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")
(为我工作)你在页面上测试了吗?我收到了这个错误:raise TimeoutException(message,screen,stacktrace)selenium.common.exceptions.TimeoutException:message:Screenshot:available viascreen@LuisRamonRamirezRodriguez是的,为我工作。我有一个更新的答案,确保你已经尝试了最新版本的答案它工作得很好。有没有优化的方法 等待的时间?@LuisRamonRamirezRodriguez太好了,等待画面出现需要多长时间?