如何只为标签获取元素定位器?

时间:2016-05-18 03:49:57

标签: selenium-webdriver

enter image description here我有一个web元素,其HTML编写为:

<div class="tabsContent">
<div id="whenGetPaid" class="txtRight oRight">
<div class="oClearBoth"></div>
<section id="adjustmentsSection">
<h2>Other Payments and Adjustments</h2>
<table class="oTableLite oTableFixedPrice">
<thead>
<tbody>
<tr>
<tr>
<tr>
<tr>
<tr>
<td>Pending</td>
<td>
<strong>Bonus</strong>
<br>
<a href="/d/contracts/14233120">c1 em16042211001803 - test:</a>
Bonus Offer
</td>
<td class="txtRight">$1,000.00</td>
</tr>
<tr>
<tr>
<tr>
<tr class="oSumRow">
</tbody>
</table>
</section>
</div>

我需要找到文本'Bonus Offer'的元素定位器,因为除了标签之外似乎没有与之关联的标签。

我目前正在使用:

//a[contains(text(), 'em16042211001803 - test')]/../following-sibling:://[text()='Bonus Offer']

以下兄弟之前的部分工作正常。我想要那之后的部分。

任何建议都会有很大的帮助。

4 个答案:

答案 0 :(得分:1)

我认为这应该有效 -

#include <iostream>
#include <string>
using namespace std;


int main()
{
int salary, x, y;
string name;
int Arr1[5];
int Arr2[5];
x = 0;
y = 0;
for (int i = 0; i <= 5; i++) {
    cin >> Arr1[name];
    cin >> Arr2[x];
    if (x > y) {
        x = y;
    }
}
cout << "Employee" << Arr1[name]<< "has the biggest salary of:" << y << endl;
return 0;
}

enter image description here

答案 1 :(得分:0)

尝试使用以下xpath执行代码。希望它能起作用。

db.collection.find(
    { $and: [
        { "factors": { $elemMatch: { "name": "f1", "value": "cat" } } }, 
        { "factors": { $elemMatch: { "name": "f3", "value": "rain" } } } 
    ]}
)

如果您遇到任何问题,请与我们联系。

答案 2 :(得分:0)

嗨,请按照以下方式进行操作

This will print the complete text inside the desired Td tag

String LabelText = driver.findElement(By.xpath("//*[@class='oTableLite oTableFixedPrice']/tbody/tr[5]/td[2]")).getText();
System.out.println("Text inside the td tag is  : " + LabelText);

// now extract your desired text like below 

String[] RealText = LabelText.split("test:");
System.out.println("label text is : " + RealText[1]);

希望这有助于你

答案 3 :(得分:0)

使用以下代码段:

  String cellText = driver.findElement(By.cssSelector("#adjustmentsSection > table > tbody > tr:nth-child(5) > td:nth-child(2)")).getText();
  String bonusOfferText  = cellText.split(":")[1].trim();