元素无可见

时间:2016-07-06 07:54:07

标签: javascript selenium-webdriver

我是自动化新手。我自动化了我公司网站的一个页面。 在编写脚本时,我面临的情况是,在检测到一个Label文本(用Sky Blue着色)时,我的代码被写为错误 '元素当前不可见,因此可能无法与'进行交互',但标签文字可以正常显示和点击。

我尽最大努力找到这个标签元素,但仍然存在错误。所以我假设由于Label Text颜色,我的webdriver没有检测到这个标签并记录这个错误。

现在我担心的是。是否有可能由于标签文本中使用的颜色而导致标签不可见。

请告知。

先谢谢

添加代码和HTML

Public WebElement GetDataSourceListByID(List<WebElement>  Tables){
      WebElement lstSearchFields;    
      WebElement fieldTable = null;
      WebElement weTemp = null;
      String tDataSourceId = null;
      Actions Visible;               

      for(WebElement we : Tables){
          List<WebElement> x = we.findElements(By.xpath("//*/div[contains(@id, 'treeview')]"));           
          for (WebElement c : x ){
              System.out.println("____________"+c.getAttribute("id"));
              c.findElement(By.xpath("//*/span[contains(text(), 'Manage Stores')]")).click();
          }

      }

      return fieldTable;              
    }

HTML CODE

<div class="x-grid-item-container" style="width: 260px;">
<table id="treeview-1165-record-310" data-boundview="treeview-1165" data-recordid="310" data-recordindex="0" class="x-grid-item x-grid-item-selected" style=";width:0" cellpadding="0" cellspacing="0">
<tbody>
<tr class="  x-grid-row" data-qtip="" data-qtitle="">
<td class="x-grid-cell x-grid-td x-grid-cell-treecolumn-1163 x-grid-cell-treecolumn x-grid-cell-first x-unselectable" style="width: 220px;" tabindex="-1" data-columnid="treecolumn-1163">
<div unselectable="on" class="x-grid-cell-inner x-grid-cell-inner-treecolumn" style="text-align:left;"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class=" x-tree-elbow-img x-tree-elbow-plus x-tree-expander" role="presentation"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" role="presentation" class=" x-tree-icon x-tree-icon-parent edge-store-png"><span class="x-tree-node-text ">Stores</span></div>
            </td>
            <td class="x-grid-cell x-grid-td x-grid-cell-actioncolumn-1164  x-action-col-cell x-grid-cell-last x-unselectable" style="width:40px;" tabindex="-1" data-columnid="actioncolumn-1164">
                <div unselectable="on" class="x-grid-cell-inner x-grid-cell-inner-action-col" style="text-align:left;"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-action-col-icon x-action-col-0   refreshIcon" data-qtip="Refresh"></div>
            </td>
        </tr>
    </tbody>
</table>
<table id="treeview-1165-record-311" data-boundview="treeview-1165" data-recordid="311" data-recordindex="1" class="x-grid-item" style=";width:0" cellpadding="0" cellspacing="0">
    <tbody>
        <tr class="dvp-tree-node-disabled x-grid-tree-node-expanded  x-grid-row" data-qtip="" data-qtitle="">
            <td class="x-grid-cell x-grid-td x-grid-cell-treecolumn-1163 x-grid-cell-treecolumn x-grid-cell-first x-unselectable" style="width: 220px;" tabindex="-1" data-columnid="treecolumn-1163">
                <div unselectable="on" class="x-grid-cell-inner x-grid-cell-inner-treecolumn" style="text-align:left;"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class=" x-tree-elbow-img x-tree-elbow-plus x-tree-expander" role="presentation"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" role="presentation" class=" x-tree-icon x-tree-icon-parent edge-workfolder-png"><span class="x-tree-node-text ">Search Folders</span></div>
            </td>
            <td class="x-grid-cell x-grid-td x-grid-cell-actioncolumn-1164  x-action-col-cell x-grid-cell-last x-unselectable" style="width:40px;" tabindex="-1" data-columnid="actioncolumn-1164">
                <div unselectable="on" class="x-grid-cell-inner x-grid-cell-inner-action-col" style="text-align:left;"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-action-col-icon x-action-col-0   no-icon" data-qtip="Refresh"></div>
            </td>
        </tr>
    </tbody>
</table>
<table id="treeview-1165-record-318" data-boundview="treeview-1165" data-recordid="318" data-recordindex="2" class="x-grid-item" style=";width:0" cellpadding="0" cellspacing="0">
    <tbody>
        <tr class="dvp-tree-node-disabled  x-grid-row" data-qtip="M_test" data-qtitle="">
            <td class="x-grid-cell x-grid-td x-grid-cell-treecolumn-1163 x-grid-cell-treecolumn x-grid-cell-first x-unselectable" style="width: 220px;" tabindex="-1" data-columnid="treecolumn-1163">
                <div unselectable="on" class="x-grid-cell-inner x-grid-cell-inner-treecolumn" style="text-align:left;"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class=" x-tree-elbow-img x-tree-elbow-line" role="presentation"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class=" x-tree-elbow-img x-tree-elbow-plus x-tree-expander" role="presentation"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" role="presentation" class=" x-tree-icon x-tree-icon-parent edge-workfolder-png"><span class="x-tree-node-text ">M_test</span></div>
            </td>
            <td class="x-grid-cell x-grid-td x-grid-cell-actioncolumn-1164  x-action-col-cell x-grid-cell-last x-unselectable" style="width:40px;" tabindex="-1" data-columnid="actioncolumn-1164">
                <div unselectable="on" class="x-grid-cell-inner x-grid-cell-inner-action-col" style="text-align:left;"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-action-col-icon x-action-col-0   no-icon" data-qtip="Refresh"></div>
            </td>
        </tr>
    </tbody>
</table>
<table id="treeview-1165-record-319" data-boundview="treeview-1165" data-recordid="319" data-recordindex="3" class="x-grid-item" style=";width:0" cellpadding="0" cellspacing="0">
    <tbody>
        <tr class="x-grid-tree-node-leaf  x-grid-row" data-qtip="Darshan (3)" data-qtitle="">
            <td class="x-grid-cell x-grid-td x-grid-cell-treecolumn-1163 x-grid-cell-treecolumn x-grid-cell-first x-unselectable" style="width: 220px;" tabindex="-1" data-columnid="treecolumn-1163">
                <div unselectable="on" class="x-grid-cell-inner x-grid-cell-inner-treecolumn" style="text-align:left;"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class=" x-tree-elbow-img x-tree-elbow-line" role="presentation"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class=" x-tree-elbow-img x-tree-elbow-end" role="presentation"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" role="presentation" class=" x-tree-icon x-tree-icon-leaf edge-searchfolder-png"><span class="x-tree-node-text ">Darshan (3)</span></div>
            </td>
            <td class="x-grid-cell x-grid-td x-grid-cell-actioncolumn-1164  x-action-col-cell x-grid-cell-last x-unselectable" style="width:40px;" tabindex="-1" data-columnid="actioncolumn-1164">
                <div unselectable="on" class="x-grid-cell-inner x-grid-cell-inner-action-col" style="text-align:left;"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-action-col-icon x-action-col-0   no-icon" data-qtip="Refresh"></div>
            </td>
        </tr>
    </tbody>
</table>
<table id="treeview-1165-record-312" data-boundview="treeview-1165" data-recordid="312" data-recordindex="4" class="x-grid-item" style=";width:0" cellpadding="0" cellspacing="0">
    <tbody>
        <tr class="dvp-tree-node-disabled x-grid-tree-node-expanded  x-grid-row" data-qtip="" data-qtitle="">
            <td class="x-grid-cell x-grid-td x-grid-cell-treecolumn-1163  edgeThemeColor x-grid-cell-treecolumn x-grid-cell-first x-unselectable" style="width: 220px;" tabindex="-1" data-columnid="treecolumn-1163">
                <div unselectable="on" class="x-grid-cell-inner x-grid-cell-inner-treecolumn" style="text-align:left;"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class=" x-tree-elbow-img x-tree-elbow-end-plus x-tree-expander" role="presentation"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" role="presentation" class=" x-tree-icon x-tree-icon-parent edge-setting"><span class="x-tree-node-text ">Manage Data Source</span></div>
            </td>
            <td class="x-grid-cell x-grid-td x-grid-cell-actioncolumn-1164  x-action-col-cell x-grid-cell-last x-unselectable" style="width:40px;" tabindex="-1" data-columnid="actioncolumn-1164">
                <div unselectable="on" class="x-grid-cell-inner x-grid-cell-inner-action-col" style="text-align:left;"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-action-col-icon x-action-col-0   no-icon" data-qtip="Refresh"></div>
            </td>
        </tr>
    </tbody>
</table>
<table id="treeview-1165-record-322" data-boundview="treeview-1165" data-recordid="322" data-recordindex="5" class="x-grid-item" style=";width:0" cellpadding="0" cellspacing="0">
    <tbody>
        <tr class="x-grid-tree-node-leaf  x-grid-row" data-qtip="" data-qtitle="">
            <td class="x-grid-cell x-grid-td x-grid-cell-treecolumn-1163  edgeThemeColor x-grid-cell-treecolumn x-grid-cell-first x-unselectable" style="width: 220px;" tabindex="-1" data-columnid="treecolumn-1163">
                <div unselectable="on" class="x-grid-cell-inner x-grid-cell-inner-treecolumn" style="text-align:left;"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class=" x-tree-elbow-img x-tree-elbow-empty" role="presentation"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class=" x-tree-elbow-img x-tree-elbow" role="presentation"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" role="presentation" class=" x-tree-icon x-tree-icon-leaf edge-store-png"><span class="x-tree-node-text ">Manage Stores</span></div>
            </td>
            <td class="x-grid-cell x-grid-td x-grid-cell-actioncolumn-1164  x-action-col-cell x-grid-cell-last x-unselectable" style="width:40px;" tabindex="-1" data-columnid="actioncolumn-1164">
                <div unselectable="on" class="x-grid-cell-inner x-grid-cell-inner-action-col" style="text-align:left;"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-action-col-icon x-action-col-0   no-icon" data-qtip="Refresh"></div>
            </td>
        </tr>
    </tbody>
</table>
<table id="treeview-1165-record-323" data-boundview="treeview-1165" data-recordid="323" data-recordindex="6" class="x-grid-item" style=";width:0" cellpadding="0" cellspacing="0">
    <tbody>
        <tr class="x-grid-tree-node-leaf  x-grid-row" data-qtip="" data-qtitle="">
            <td class="x-grid-cell x-grid-td x-grid-cell-treecolumn-1163  edgeThemeColor x-grid-cell-treecolumn x-grid-cell-first x-unselectable" style="width: 220px;" tabindex="-1" data-columnid="treecolumn-1163">
                <div unselectable="on" class="x-grid-cell-inner x-grid-cell-inner-treecolumn" style="text-align:left;"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class=" x-tree-elbow-img x-tree-elbow-empty" role="presentation"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class=" x-tree-elbow-img x-tree-elbow" role="presentation"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" role="presentation" class=" x-tree-icon x-tree-icon-leaf edge-connector-png"><span class="x-tree-node-text ">Manage Connectors</span></div>
            </td>
            <td class="x-grid-cell x-grid-td x-grid-cell-actioncolumn-1164  x-action-col-cell x-grid-cell-last x-unselectable" style="width:40px;" tabindex="-1" data-columnid="actioncolumn-1164">
                <div unselectable="on" class="x-grid-cell-inner x-grid-cell-inner-action-col" style="text-align:left;"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-action-col-icon x-action-col-0   no-icon" data-qtip="Refresh"></div>
            </td>
        </tr>
    </tbody>
</table>
<table id="treeview-1165-record-324" data-boundview="treeview-1165" data-recordid="324" data-recordindex="7" class="x-grid-item" style=";width:0" cellpadding="0" cellspacing="0">
    <tbody>
        <tr class="x-grid-tree-node-leaf  x-grid-row" data-qtip="" data-qtitle="">
            <td class="x-grid-cell x-grid-td x-grid-cell-treecolumn-1163  edgeThemeColor x-grid-cell-treecolumn x-grid-cell-first x-unselectable" style="width: 220px;" tabindex="-1" data-columnid="treecolumn-1163">
                <div unselectable="on" class="x-grid-cell-inner x-grid-cell-inner-treecolumn" style="text-align:left;"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class=" x-tree-elbow-img x-tree-elbow-empty" role="presentation"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class=" x-tree-elbow-img x-tree-elbow-end" role="presentation"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" role="presentation" class=" x-tree-icon x-tree-icon-leaf edge-rule-png"><span class="x-tree-node-text ">Manage Rules</span></div>
            </td>
            <td class="x-grid-cell x-grid-td x-grid-cell-actioncolumn-1164  x-action-col-cell x-grid-cell-last x-unselectable" style="width:40px;" tabindex="-1" data-columnid="actioncolumn-1164">
                <div unselectable="on" class="x-grid-cell-inner x-grid-cell-inner-action-col" style="text-align:left;"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-action-col-icon x-action-col-0   no-icon" data-qtip="Refresh"></div>
            </td>
        </tr>
    </tbody>
</table>

2 个答案:

答案 0 :(得分:0)

在点击按钮

之前尝试使用显式等待
SELECT id, name, 
  (SELECT B.name from `users` B WHERE B.id = A.bossid) bossname 
  FROM `users` A

答案 1 :(得分:0)

我只是在for循环中做了一些改变。请更换下面的for循环并尝试执行代码。

for(WebElement we:Tables)        {            列表x = we.findElements(By.cssSelector(&#34; table [id ^ =&#39; treeview&#39;]&#34;));
           for(WebElement c:x)            {                的System.out.println(&#34; ____________&#34 + c.getAttribute(&#34; ID&#34));                c.findElement(By.xpath(&#34; // * [contains(text(),&#39; Manage Stores&#39;)]&#34;))。click();            }        }

我找到了id&#39; treeview&#39;出现在id值的开头,所以我使用了css选择器&#34; id ^&#34; - 它以“树视图”开头给出了id。

希望你的问题得到解决。如果需要更多帮助,请回复。