[Selenium]How to click on a hidden link ,mov
系統
1778 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元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元