selenium处理 <a target=_blank 几种方式整理(转)

selenium处理 <a target=_blank 几种方式整理

方法1.取 href ,再用open(当时是为了走通流程)
1.jpg



方法2.修改被测页面的<a> 元素打开页面的方式

  1.                               
  2. //模拟打开子窗口
  3. //用窗口打开
  4. selenium.getEval("this.page().findElement(\""+picXpath+"\").removeAttribute('target')");
  5. selenium.getEval("this.page().findElement(\""+picXpath+"\").href=\"javascript:window.open('"+picUrl+"','p4pwindow','scrollbars=yes')\"");
  6. selenium.click(picXpath);
  7. Thread.sleep(100);
  8. selenium.selectWindow("name=p4pwindow");                               
  9. String bigPic=selenium.getAttribute("//img[@id='J_ImgBooth']@src");
  10.                                
  11. //add code
  12. selenium.getEval("javascript:window.close();");
  13. selenium.selectWindow("name=mywindow");
复制代码


方法3:在单击弹出后,用selenium.getAllWindowTitles(),取最后一个title(这个我暂时没有用到,因title都一样)
selenium.click(picXpath);
String[] titles=selenium.getAllWindowTitles();
selenium.selectWindow("title="+titles[titles.length-1]+"");
//add code
selenium.close();



方法4:autoit, 一点点来模拟.(vbs,代码片)Set  objArgs = WScript.Arguments
Set oAutoIt = CreateObject("AutoItX3.Control")
oAutoIt.WinActivate "untitled", ""
oAutoIt.WinWaitActive "untitled","",5
oAutoIt.MouseClick "left", objArgs(0), objArgs(1), 1

rem
oAutoIt.AutoItSetOption "WinTitleMatchMode", 2
'set title = oAutoIt.WinGetTitle("_更多", "")
oAutoIt.WinActivate "_更多", ""
oAutoIt.WinWaitActive "_更多", "",5

方法5:可以采用弹出窗口-设置成在原有的窗口中大打开就可以了
selenium.runScript("var frame = document.getElementById('ygmasrchfrm');frame.target='_self'");

‘ygmasrchfrm' 这个是点击后会弹出窗口的link的ID。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值