当前位置: 动力学知识库 > 问答 > 编程问答 >

How to Click the hyper Links in the table columns of webpage using Selenium web driver and how to store it

问题描述:

Here is my HTML Script:

  1. How to capture the link element in the tenth row?

    HTML image

     <table id="dataTableParticipantSearchResults" class="display" width="100%" cellspacing="0" cellpadding="0" border="0">

    <thead>

    <tr align="left">

    <th class="ui-state-default" width="20%" style="width: 154px;">

    <div class="DataTables_sort_wrapper"></div>

    </th>

    <th class="ui-state-default" width="20%" style="width: 96px;"></th>

    <th class="ui-state-default" width="15%" style="width: 69px;"></th>

    <th class="ui-state-default" width="10%" style="width: 44px;"></th>

    <th class="ui-state-default" width="20%" style="width: 156px;"></th>

    <th class="ui-state-default" width="15%" style="width: 68px;"></th>

    </tr>

    </thead>

    <tbody>

    <tr class="odd" align="left">

    <td><a href="LINK"></a></td>

    </tr>

网友答案:

You can always find these kinds of hyperlinks by first identifying the root table id- in this case it will be like this:

WebElement table = driver.findelement(by.id("dataTableParticipantSearchResults"));

Now you can use Xpath or Css Selector to select the link

try this:

table.findelement(by.cssSelector("a[href='LINK']")).click();

or try

table.findelement(by.linktext("LINK")).click();

or try

table.findelement(by.xpath(".//*[@id='dataTableParticipantSearchResults']/tbody/tr/td[0]")).click();

let me know if these work....cheers !

网友答案:

U can store the value in a WebElement and call any number of times.

WeElement link = table.findelement(by.xpath(".//*[@id='dataTableParticipantSearchResults']/tbody/tr/td[9]"));

now call it any number of times:

link.click();---------1st time

link.click();--------- 2nd time

and so on.....cheers !

分享给朋友:
您可能感兴趣的文章:
随机阅读: