处理框架 - Python Webdriver
Dealing with Frames - Python Webdriver
我有以下代码,它正在寻找两个框架,然后单击 link。
此代码适用于 Chrome 和 Firefox。在 IE 中,虽然测试只是位于此页面上,但根本不做任何事情。在 Safari 中,我收到一个框架不存在的错误,这是胡说八道,正如我在 Safari 开发人员工具中看到的那样。所以我想知道如何使它在所有浏览器中工作。
try:
iframe = driver.find_element_by_id('iFrm')
driver.switch_to_frame(iframe)
print "Navigated to iFrm frame"
except:
raise InvalidSwitchToTargetException(msg="Couldn't find the iFrm frame")
try:
nav_frame = driver.find_element_by_id('nav')
driver.switch_to_frame(nav_frame)
print "Navigated to nav frame"
except:
raise InvalidSwitchToTargetException(msg="Couldn't find the nav frame")
Explicit Wait让框架出现在 Safari 的情况下会有帮助:
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(browser, 10)
frame = wait.until(EC.presence_of_element_located((By.ID, 'iFrm')))
driver.switch_to_frame(frame)
我有以下代码,它正在寻找两个框架,然后单击 link。
此代码适用于 Chrome 和 Firefox。在 IE 中,虽然测试只是位于此页面上,但根本不做任何事情。在 Safari 中,我收到一个框架不存在的错误,这是胡说八道,正如我在 Safari 开发人员工具中看到的那样。所以我想知道如何使它在所有浏览器中工作。
try:
iframe = driver.find_element_by_id('iFrm')
driver.switch_to_frame(iframe)
print "Navigated to iFrm frame"
except:
raise InvalidSwitchToTargetException(msg="Couldn't find the iFrm frame")
try:
nav_frame = driver.find_element_by_id('nav')
driver.switch_to_frame(nav_frame)
print "Navigated to nav frame"
except:
raise InvalidSwitchToTargetException(msg="Couldn't find the nav frame")
Explicit Wait让框架出现在 Safari 的情况下会有帮助:
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(browser, 10)
frame = wait.until(EC.presence_of_element_located((By.ID, 'iFrm')))
driver.switch_to_frame(frame)