【发布时间】:2020-09-15 11:35:01
【问题描述】:
我无法在自动化代码中切换 iframe(我必须使用 python、selenium 从 kaggle 下载数据集)。这个 iframe 没有 id,也没有名字,只有 src。
我附上了 iframe HTML 的图片,否则看起来像这样:
> <iframe height="0" width="0" tabindex="-1"
> src="https://accounts.youtube.com/accounts/CheckConnection?pmpo=https%3A%2F%2Faccounts.google.com&v=-1287755822&timestamp=1600168651416"
> style="position: absolute; left: 0px; top: 0px; z-index:
> -1;"></iframe>
我的代码是:
def access_website():
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://www.kaggle.com/c/titanic/data?select=train.csv')
sleep(1)
driver.find_element_by_xpath("/html/body/main/div[1]/div/div[6]/div/div[2]/div").click() #click new page
driver.find_element_by_xpath("/html/body/main/div[1]/div/div[5]/div[2]/div/div[2]/div[4]/div/div[1]/div[3]/button").click()#click download dataset
#Google login appears
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
代码返回:“消息:没有这样的元素:无法找到元素:{“method”:“xpath”,“selector”等”
【问题讨论】:
标签: python-3.x selenium selenium-webdriver selenium-chromedriver