WebDriver:如何切换到没有名称或 ID 的 iframe?
WebDriver: How could one switch to an iframe without a name nor ID?
我正在尝试按下 iframe 中的按钮。
我无法切换到它,因为它没有 ID,而且它的名称是随机生成的。
如果没有名称或 ID,我怎么能切换到它呢?
我以为我可以通过它的标题切换到它,但遗憾的是我不能。
我试过这个:
def pressbutton():
time.sleep(3)
WebDriverWait(chrome, 0).until(EC.element_to_be_clickable((By.XPATH,"(//div[contains(.,'Something')])[last()]"))).click()
time.sleep(2)
chrome.switch_to.frame("a-v5kdywa4uk15") #Its name that is being randomly generated
chrome.find_element_by_xpath("//div[@class='Button']").click()
原来你可以通过它的 xpath 找到一个特定的 iframe:
iframe = chrome.find_element_by_xpath("//iframe[@title='Your iframe Title']")
driver.switch_to.frame(iframe)
我正在尝试按下 iframe 中的按钮。 我无法切换到它,因为它没有 ID,而且它的名称是随机生成的。 如果没有名称或 ID,我怎么能切换到它呢? 我以为我可以通过它的标题切换到它,但遗憾的是我不能。
我试过这个:
def pressbutton():
time.sleep(3)
WebDriverWait(chrome, 0).until(EC.element_to_be_clickable((By.XPATH,"(//div[contains(.,'Something')])[last()]"))).click()
time.sleep(2)
chrome.switch_to.frame("a-v5kdywa4uk15") #Its name that is being randomly generated
chrome.find_element_by_xpath("//div[@class='Button']").click()
原来你可以通过它的 xpath 找到一个特定的 iframe:
iframe = chrome.find_element_by_xpath("//iframe[@title='Your iframe Title']")
driver.switch_to.frame(iframe)