How to write XPATH for the below span class element in Selenium?
<span class ="menu-item-text">
<span class ="menu-text">Selenium</span>
</span>
You can get the text "Selenium" by using the xpath:
WebElement element = driver.findElement(By.xpath("//span[@class='menu-text']"));
String elementText = element.getText();
However, you can also fetch the text by using the classname in this case like:
WebElement element = driver.findElement(By.className("menu-text"));
String elementText = element.getText();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.