在selenium JAVA中提取文本br标签

时间:2018-05-04 16:42:51

标签: java selenium-webdriver

我需要获得“德克萨斯州 - 美国”和“美国”的文本。 'Illinois-United States',以便我可以在字符串匹配后点击文本上方的超链接。我尝试了以下方法,但无法做到这一点。任何人都可以帮助

print(df)

      AutomationStatus  TestPriority
0                 Done             4
1                 Done             4
2                 Done             4
3      WillNotAutomate             3
4                 Done             4
5  ReviewforAutomation             3
6  ReviewforAutomation             3
7  ReviewforAutomation             3

df['AutomationStatus'] = np.where(df['AutomationStatus'] == 'Done',
                                  'Automated', 'ManualTest')

res = df.pivot_table(index='AutomationStatus', columns=['TestPriority'],
                     aggfunc=len, fill_value=0)

print(res)

TestPriority      3  4
AutomationStatus      
Automated         0  4
ManualTest        4  0

下面的HTML供参考

findElement(By.xpath("//html/body/font/nobr")).getAttribute("innerHTML")
findElement(By.xpath("//html/body/font/nobr")).getAttribute("textContent")
findElement(By.xpath("//html/body/font/nobr")).getText()
findElement(By.xpath("//html/body/font/nobr/text()[preceding-sibling::br]")).getText()
findElement(By.xpath("//html/body/font/nobr/a[1]")).getText()
findElement(By.xpath("//html/body/font/nobr/a[1][following-sibling::node()[1][self::BR]]")).getAttribute("innerHTML")

3 个答案:

答案 0 :(得分:1)

如果您想点击上面的链接,可以使用以下代码:

a:1:{s:4:"hash";s:60:"$2y$10$myhashishere";}

findElement(By.xpath("//text()[contains(., 'Texas-United States')]/preceding-sibling::a[1]")).click()

答案 1 :(得分:0)

要识别德克萨斯州 - 美国文本,并在您可以使用的文字上方的超链接上调用click()

driver.findElement(By.xpath("//nobr//br[normalize-space()='Texas-United States']//preceding::a[1]")).click();

要识别伊利诺伊州 - 美国文本,并在您可以使用的文字上方的超链接上调用click()

driver.findElement(By.xpath("//nobr//br[normalize-space()='Illinois-United States']//preceding::a[1]"))click();

答案 2 :(得分:-2)

请尝试:

findElement(By.xpath("//html/body/font/nobr")).getAttribute("innerText")
相关问题