当前位置:首页>开发>正文

selenium怎么处理iframe定位 selenium拖拽跨iframe怎么处理

2023-07-16 07:21:47 互联网 未知 开发

 selenium怎么处理iframe定位 selenium拖拽跨iframe怎么处理

selenium怎么处理iframe定位

先切换到iframe层,然后再进行元素的定位和处理,java代码示例
dr.switchTo().frame(dr.findElement(By.id("iFrame_id")))
操作完成,如需切换回父级页面
dr.switchTo().parentFrame()

selenium拖拽跨iframe怎么处理

1. dragAndDrop(locator, movementsString)
2. 使用鼠标事件模拟拖拽。mouseDownAt、mouseMove、mouseUpAt等可组合使用,逐一拖拽的坐标取值

怎样开始用selenium进行自动化测试

selenium 是一款开源的自动化测试框架,可以有两种开始学习的方式。第一种是使用selenium的IDE进行录制和回放脚本,这个IDE是Firefox的一个插件,网上有很多介绍和下载地址。这一种方式主要是刚接触selenium时,当对selenium的相关原理了解之后,可以开始第二种开始方式,这种方式涉及到代码编写,selenium支持很多种语言作为脚本,本人推荐java或者python。第二种方式主要是根据测试的需要,进行脚本的优化以及测试数据参数化等。

当第二种方式比较熟悉之后,你就可以考虑进行基于selenium的二次开发,形成适合自己的自动化测试框架了。

selenium2元素定位问题

两xpath都有问题:
先说第一个那个id很明显后面是一个随机数,要是数据变化那个ID肯定不好使的。
再说第二xpath也是应该://form[@id=queryForm]//input[@id=addButton]
建议办法:
我如果猜得没错的话,你这个整个都是一个表单,一个大表单里又有若干小表单cleverTabPanelItem。然后每个cleverTabPanelItem这种元素里其实都有addButton这个ID的button. 所以你这个应该写以方法对整个大表单操作,传入行、列值进去,返回单元格WebElement对象,你再想做什么操作就方便了。而不是直接定位点。那下次换个位置不就哭了?

selenium webdriver定位iframe里的body方法?

1.iFrame有ID 或者 name的情况
//进入id="frame1"的frame中,定位id="div1"的div和id="input1"的输入框。
dr.switchTo().frame("frame1")
dr.findElement(By.id("div1"))
dr.findElement(By.id("input1"))

2.如果一个iFrame既没有id,也没有name,通用情况
// 定位frame位置,并选取frame
WebElement frame=driver.findElement(By.xpath( "/html/body/div[2]/div[8]/div[2]/div[3]/div/div

[2]/div/iframe" ))
driver.switchTo().frame(frame)

3.跳出iFrame
//跳出frame,进入default content重新定位id="id1"的div
dr.switchTo().defaultContent()
dr.findElement(By.id("id1"))

selenium2.0的switchTo().frame(0)的问题

1、2、3的回答:

你对方法frame(index)的index理解是对的,具体如下:
Select a frame by its (zero-based) index. That is, if a page has three frames,
the first frame would be at index "0", the second at index "1" and the third at
index "2". Once the frame has been selected, all subsequent calls on the
WebDriver interface are made to that frame.
Parameters:
index (zero-based) index
Returns:
This driver focused on the given frame
Throws:
NoSuchFrameException
- If the frame cannot be found
第4的回答:(看下面这个)
jarvi.iteye.com/blog/145052
By the way: 你说的iframe都没有id,name之类,请把这个iframe在firebug里的源码截图上来看一下

最新文章