我正在使用selenium webdriver和它的新手。我需要帮助。我的Xpath如下所示:
html/body/div[1]/section/div/div/div/div/div[1]/div[1]/div[2]/ul/li[1]/div/span代码:
<div class="mod-content">
<ul id="issuedetails" class="property-list two-cols">
<li class="item">
<div class="wrap">
<strong class="name">Type:</strong>
<span id="type-val" class="value">
<img width="16" height="16" title="Provision access - HUE" src="/secure/viewavatar?size=xsmall&avatarId=10318&avatarType=issuetype" alt=""/>
Provision access - HUE
</span>
</div>我想要捕获文本"Provision access - HUE“。但是当我使用Selenium webdriver 2时
WebElement Type = driver.findElement(By.xpath("//*/span[@id='type-val]"));
System.out.println("Type is "+Type.getText());//Printing Type我得到的输出是"Type is Access Request“。
发布于 2016-08-18 19:58:24
我认为有多个span元素的类名为value,而您正在定位其他span,因为findElement总是返回第一个匹配的定位器元素,您需要创建唯一的定位器来定位您想要的元素,可能id在这里是唯一的,所以您应该尝试使用By.id(),如下所示:
WebElement Type = driver.findElement(By.id("type-val"));
System.out.println("Type is "+Type.getText());如果id在这里也不是唯一的,请尝试使用下面的xpath :-
WebElement Type = driver.findElement(By.xpath(".//strong[contains(text(), 'Type:')]/following-sibling::span[@id = 'type-val']"));
System.out.println("Type is "+Type.getText());https://stackoverflow.com/questions/39017498
复制相似问题