Ruby Selenium Web驱动程序:如何通过匹配子字符串的类名来查找子元素

时间:2017-04-07 02:47:00

标签: ruby selenium svg xpath

新手硒程序员请帮助我...

我有html以下,我试图通过下面的html

中的子串svg的类名来查找deleteIcon子元素
<div class="result-controls">
   <div class="attachment">
      <li class="add-attachment-button-column"><a><button>ADD ATTACHMENTS</button></a></li><input type="file" multiple="" style="display: none;">
   </div>
   <li class="sign-button-column"><a href="javascript:void(0)"><button>SIGN</button></a></li>
   <li class="draft-button-column"><a><button>DRAFT</button></a></li>
   <li class="delete-column"> <a href="javascript:void(0)"><svg class="glyphicon-trash deleteIcon" viewBox="0 0 100 100"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#trash"></use></svg> </a></li>
</div>

我正在尝试找到svg元素类匹配&#39; deleteIcon&#39; (row变量高于html)

  row.find_element(:xpath => "./li/a/svg[contains(@class,'deleteIcon')]")

但是我遇到了异常

*** Element info: {Using=xpath, value=./li/a/svg[contains(@class,'deleteIcon')]} (org.openqa.selenium.NoSuchElementException)

任何人都可以使用selenium web驱动程序在Ruby中帮助我吗?

1 个答案:

答案 0 :(得分:1)

您无法在xpath表达式中使用ID COUNTRY_CODE SEND_INVITES MEMBER_RECEIVED_INVITES DOI_DATE1 DATE_CREATED1 Month1 Month2 Month3 1170309479 US 1 1 12/22/2016 1/14/2017 1/21/2017 2/20/2017 3/22/2017 1167268031 US 1 1 12/4/2016 1/6/2017 1/3/2017 2/2/2017 3/4/2017 1168417033 US 1 1 12/11/2016 1/6/2017 1/10/2017 2/9/2017 3/11/2017 1133456595 CA 1 1 10/31/2016 12/13/2016 11/30/2016 12/30/2016 1/29/2017 1026176359 CA 1 1 7/8/2016 9/20/2016 8/7/2016 9/6/2016 10/6/2016 1170285089 GB 1 1 12/23/2016 12/23/2016 1/22/2017 2/21/2017 3/23/2017 作为标记名称。请尝试使用xpath,

svg