有类和标记名,我正在编写下面的 selenium 代码以从下面的代码中查找描述,但它不起作用。
WebElement WWdescription = driver.findElement(By.className("atb-delivery-accordions").className("section highlight-01").tagName("p"));
<div class="atb-delivery-accordions">
<div class="page-accordion opened">
<input id="moreDetails-acc" class="acc-check" type="checkbox" checked="">
<label class="acc-label opened" data-panel-id="moreDetailsAcc" for="moreDetails-acc">Description</label>
<div class="content" data-panel-id="moreDetailsAcc" style="display: block;">
<div class="information-panel">
<div class="subcontent">
<div class="section highlight-01">
<p>A pretty floral lace collection combining contrast bows and trims for a feminine on trend look. The fuller coverage of our post surgery bras provide support, comfort and confidence. The dual cotton pockets are perfect for a prosthesis. Combine style and value with this pack of 2 bras.</p>
最佳答案
尝试这样的事情:
WebElement parentEle = driver.findElement(By.xpath("//div[@class='atb-delivery-accordions']"));
WebElement descriptionEle = parentEle.findElement(By.tagName("p"));
//Get the text from the description element.
String descriptionText = descriptionEle.getText();
关于java - 使用 selenium webdriver 按类名和标记名查找元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31963439/