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

来源:互联网 发布:淘宝怎么更换支付宝 编辑:程序博客网 时间:2024/06/05 03:01

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

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




方法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
0 0
原创粉丝点击