本文介绍了在Selenium WebDriver上如何从Span标签获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Selenium Webdriver上,我可以如何从span标签&打印?我需要提取文本 - UPS隔夜 - 免费
HTML代码如下:
div id =customSelect_3class =select_wrapper>
< div class =select_display hovered>
String kk = wd.findElement(By.xpath(// * [@ id ='customSelect_3'] / div [1] /跨度))的getText();
System.out.println(kk);
但上述代码正在返回/打印文本 - 1。
解决方案
我同意css更好。如果你真的想通过Xpath来做,你可以试试:
String kk = wd.findElement(By.xpath(./ / * div [@ id ='customSelect_3'] / div / span [@ class ='selectLabel clear']。getText()))
On Selenium Webdriver, how I can retrive text from a span tag & print?
I need to extract the text - "UPS Overnight - Free"
HTML code are as follow:div id="customSelect_3" class="select_wrapper"><div class="select_display hovered"><span class="selectLabel clear">UPS Overnight - Free</span>
Using following code:
String kk = wd.findElement(By.xpath(//*[@id='customSelect_3']/div[1]/span)).getText();
System.out.println(kk);
But above code is returning/printing text - "1".
解决方案
I agree css is better. If you did want to do it via Xpath you could try:
String kk = wd.findElement(By.xpath(.//*div[@id='customSelect_3']/div/span[@class='selectLabel clear'].getText()))
这篇关于在Selenium WebDriver上如何从Span标签获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!