如何使用 Selenium 和 Java 识别元素
How to identify the element using Selenium and Java
我正在尝试识别元素。我想识别 "address your concerns."。我最多可以访问 div 标签,但我需要访问 div 标签中的文本。
HTML:
<span class="Linkify">
<div>
<div>
address your concerns.
</div>
</div>
</span>
我正在尝试识别文本 "address your concerns" 所以有人可以在 chrome 浏览器中帮我解决这个问题吗?
尝试使用 XPath 来定位您的 div 元素,例如“//span[@class='Linkify']/div/div”,然后使用div 上的 getText() 方法以获取您的文本。
使用 you need to induce for the visibilityOfElementLocated()
and you can use either of the following 识别元素:
cssSelector:
WebElement cssElement = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("span.Linkify > div > div")));
xpath:
WebElement xpathElement = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@class='Linkify']/div/div[contains(., 'address your concerns')]")));
我正在尝试识别元素。我想识别 "address your concerns."。我最多可以访问 div 标签,但我需要访问 div 标签中的文本。
HTML:
<span class="Linkify">
<div>
<div>
address your concerns.
</div>
</div>
</span>
我正在尝试识别文本 "address your concerns" 所以有人可以在 chrome 浏览器中帮我解决这个问题吗?
尝试使用 XPath 来定位您的 div 元素,例如“//span[@class='Linkify']/div/div”,然后使用div 上的 getText() 方法以获取您的文本。
使用visibilityOfElementLocated()
and you can use either of the following
cssSelector:
WebElement cssElement = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("span.Linkify > div > div")));
xpath:
WebElement xpathElement = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@class='Linkify']/div/div[contains(., 'address your concerns')]")));