Selenium定位器 - 具有相同类别的Div元素

时间:2017-10-24 00:30:38

标签: selenium classname

我正在尝试访问具有相同类名的元素。请查看我的页面结构,它是这样的:

<div class="class-results-list-container" >
<div class="accordionWrapper">
<div class="accordionWrapper">
   <div class="accordion-header-wrapper">
   <div class="accordion-header padded-container">
   <div class="accordion-header-left">
   <div class="acc-head-left-wrapper">
   <div class="acc-head-left-row">
   <div class="heading-text">**RAMBO**</div>
   <div class="same-game-multi-notification-wrapper hidden">
   <div class="accordion-helptext"/>
   </div>
   </div> 
   </div>
   <div class="accordion-header-right">
   </div>
   </div>
   <div class="accordion-content hidden" style="display: block;">
     </div>
<div class="accordionWrapper">
<div class="accordionWrapper">
<div class="accordionWrapper">
<div class="accordionWrapper">
<div class="accordionWrapper">

1 个答案:

答案 0 :(得分:0)

你的问题不明确。从您的HTML中我假设您可能对

中的文本感兴趣
<div class="heading-text">**RAMBO**</div>

如果是这样,您可以使用xpath "//div[@class='heading-text']"

爪哇:

    WebElement wl= driver.findElement(By.xpath("//div[@class='heading-text']"));
    System.out.println(wl.getText());

的Python:

text=driver.find_element_by_xpath("//div[@class='heading-text']")
print(text.text)

如果出于某种原因,您还需要检查此元素中的文本,则可以使用

"//div[@class='heading-text'] [text()='**RAMBO**']"