个人对webdriver的理解(三)
来源:互联网 发布:数据的存储结构是指 编辑:程序博客网 时间:2024/04/30 17:24
webdriver定位页面元素时,有时会找不到元素,有可能是因为该元素是处于框架(frame)中,webdriver查找框架中的方法很简单,先切换到frame中,然后再定位元素,我一般情况下是这么用的,不知道会不会存在什么弊端。
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.Select;
public class Test{
public static void main(String[] args){
WebDriver dr=new InternetExplorerDriver();
dr.get("http://126.com");//打开126邮箱地址;
//输入用户名、密码,选择邮箱风格,然后登陆;
dr.findElement(By.id("idInput")).clear();
dr.findElement(By.name("user")).sendKeys("账号");
dr.findElement(By.id("pwdInput")).clear();
dr.findElement(By.name("password")).sendKeys("密码");
Select style=new Select(dr.findElement(By.name("style")));
style.selectByValue("9");
style.selectByValue("-1");
dr.findElement(By.id("loginBtn")).click();
//切换到名为index的frame中;
dr.switchTo().frame("index");
//点击“收件箱”那个按钮;
dr.findElement(By.xpath("//div[@class='ns']/ul[@id='ulNavsystem']/li/a[@title='收件箱']")).click();
可以尝试,如果有没有dr.switchTo().frame("index");这条语句,看看代码是否能够找到“收件箱”按钮。
顺便说一下,我是先用chrome浏览器上自带的工具,查看了页面代码,找到登陆邮箱后,页面的frame名称为“index”。
0 0
- 个人对webdriver的理解(三)
- 个人对webdriver的理解(一)
- 个人对webdriver的理解(二)
- 个人对webdriver的理解(四)
- 个人对webdriver的理解(五)
- 个人对webdriver的理解(六)
- 个人对webdriver的理解(七)
- 个人对webdriver的理解(八)
- 个人对webdriver的理解(九)
- 个人对webdriver的理解(十)
- 个人对webdriver的理解(十一)
- 个人对webdriver的理解(十二)
- 对webdriver的理解
- 个人对getInitParameter的理解
- 个人对宏观经济学的理解
- 个人对withValueBackReference的理解
- 个人对MVC的理解
- 对SVM的个人理解
- canvas-转盘
- Scrapy 爬取 豆瓣电影的短评
- beyond compare 解决文件一样,对比有差异的问题
- qt 中都使用第三方类 :错误:ISO C++ 不允许 声明无类型的‘CClient’
- openstack RPM打包
- 个人对webdriver的理解(三)
- The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the argument
- markdown语法简记
- 手机屏幕向下滑动分页取数据
- 个人对webdriver的理解(四)
- 工薪青年如何实现在一线城市购房的梦想?
- Linux最大打开文件描述符数
- 【bzoj1901】Zju2112 Dynamic Rankings 线段树套平衡树
- java连接mysql数据库增删改查操作记录