1. 页面中嵌套了iframe后,iframe中的元素无法定位到,可通过selenium中“driver.switch_to.frame(xxx)”切换到iframe中,再进行定位元素,
2. 切到iframe中后,可通过“driver.switch_to.parent_frame()”切到上一层表单,也可通过“driver.switch_to.default_content()”切到最外层表单,也是主页面
html文件如下:
<html>
<head>
</head>
<body>
<div class = "row-fluid">
<div class = "span10 well">
<h3>frame</h3>
用户名:<input type="text", name = "jike"><br>
<iframe id = "if", name = "nf", src = "https://www.baidu.com/" width = "1000", height = "600">
</iframe>
</div>
</div>
</body>
</html>
python表单切换代码:
from selenium import webdriver
from selenium.webdriver.common.by import By