[Selenium]How to click on a hidden link ,mov

系统 1635 0
      <table id="_paid_19" class="GOMainTable" cellspacing="0" cellpadding="0">

<tbody>

<tr>

<tr>

<td style="
      
        overflow:hidden
      
      ;">

<div class="GOBodyMid" style="
      
        overflow: hidden
      
      ; width: 625px; height: 334px;">

<div class="GOPageOne">

<table class="GOSection" cellspacing="0" cellpadding="0">

<tbody>

<tr>

<tr class="GODataRow " style="height: 26px;" onmousemove="Grids[3].ARow=Grids[3].Rows["AR1"];Grids[3].ASec=0;">

<td style="width:0px;height:0px"></td>

<td class=" GOClassReadOnly highlight-tbl HoverClass GOText GOCell HideCol3displayName" colspan="2" style="">
      
        Automation Smoke test Template
      
      </td>

<td class=" GOClassReadOnly highlight-tb HoverClass GOHtml GOCell HideCol3editPencil" colspan="2" style="">


      
        <div class="edit-Pencil"></div>
      
      

</td>

<td class=" GOClassReadOnly highlight-tb b_r HoverClass GOHtml GOCell HideCol3deleteIcon" colspan="2" style="">

<td class=" GOClassReadOnly highlight-tb b_r HoverClass GODate GOCell HideCol3dateModified" colspan="2" style="">8/11/2014</td>

<td class=" GOClassReadOnly highlight-tb b_r HoverClass GOText GOCell HideCol3owner" colspan="2" style="">Rachel Lv</td>

<td class=" GOClassReadOnly highlight-tbr HoverClass GOText GOCell HideCol3permission" colspan="2" style="">Read Only</td>

<td class=" HoverClass GOHtml GOCellEmpty GOEmpty HideCol3_ConstWidth"> </td>

</tr>


    

 场景:需要找到Table中的某一行,然后找到这行的铅笔图标,点这个铅笔图标会出来下拉菜单,然后在下拉菜单中点击Open

刚开始写脚本的时候,按照以往的方式会报这样的错误: "Element is not currently visible and so may not be interacted with"

这个元素在界面上是可见的,也通过正则表达式唯一匹配到了,可是在Click的时候就是不行。

后来查阅资料,发现这个元素的父元素是 hidden 的。

原文如下:

Selenium determines an element is visible or not by the following criteria (use a DOM inspector to determine what css applies to your element, make sure you look at computed style):

  • visibility != hidden
  • display != none (is also checked against every parent element)
  • opacity != 0 (this is not checked for clicking an element)
  • height and width are both > 0
  • for an input, the attribute type != hidden

Your element is matching one of those criteria. If you do not have the ability to change the styling of the element, here is how you can forcefully do it by using Actions in the code.

后来我是这样解决的,可以成功运行了。

      Actions action =new Actions(driver);

WebElement pencilIcon = page.getPencilIcon(templateName);

action.moveToElement(pencilIcon).click();

		

WebElement menu = page.getMenu();

action.moveToElement(menu).build().perform();

Assert.assertTrue(menu.isDisplayed(),"Cannot find the menu");

		

WebElement open = page.getOpenMenu();

open.click();


    

 

[Selenium]How to click on a hidden link ,move to the drop down menu and click submenu


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论