如何在webdriver中为多个web元素获取相对XPath?
如何获得这三个元素的相对XPath,以便获得上述文本如何在webdriver中为多个web元素获取相对XPath?,xpath,selenium-webdriver,Xpath,Selenium Webdriver,如何获得这三个元素的相对XPath,以便获得上述文本 DDM IT QUIZ 2017 – Bhubaneswar Edition [Paybooks] Tax/investment declaration proof FY 2016-17 Reimbursement clarification 这将返回一个文本列表完整的答案是: 获取相同类型的所有a元素,在这种情况下,具有id和ctl00 //a[包含(@id,'ctl00')] 您可以添加更多限制,例如添加href限制,以在其值中包
DDM IT QUIZ 2017 – Bhubaneswar Edition
[Paybooks] Tax/investment declaration proof FY 2016-17
Reimbursement clarification
这将返回一个文本列表完整的答案是:
- 获取相同类型的所有
元素,在这种情况下,具有a
和id
//a[包含(@id,'ctl00')]ctl00
- 您可以添加更多限制,例如添加
限制,以在其值中包含特定字符串 //[contains(@id,'ctl00')][contains(@href,'Message')]href
- 要获取所有
元素,只需使用 //a
为了获取文本,您可以使用方法从框架中获取文本,或者将
/text()
添加到xpath表达式中。您可以使用span类[relative xpath],如以下示例所示,以及鼠标操作和键盘操作。
看看这个,让我知道
xpath = '//a/text()'
请提供网站url。请将鼠标悬停在任何类别上并单击任何项目,现在,我将如何获取例如:inside electronics>DTH Services的相对xpath非常感谢您的努力。我是否能够帮助您?是的,再次感谢。我介绍了相对路径的概念。你知道如何从页面中检索笑脸吗?&在控制台上打印。所有这些都是使用webdriver实现的。
xpath = '//a/text()'
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class SnapD {
public static void main(String args[]){
WebDriver d=new FirefoxDriver();
d.get("https://www.snapdeal.com/");
d.manage().window().maximize();
d.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
System.out.println("Hello Google...");
System.out.println("Hello Snapdeal...");
WebElement wb= d.findElement(By.xpath("//span[text()='Electronics']"));
Actions act=new Actions(d);
act.moveToElement(wb);
act.perform();
System.out.println("Mouse hovered");
WebElement wb1=d.findElement(By.xpath("//span[text()='DTH Services']"));
act.contextClick(wb1).perform();
act.sendKeys(Keys.ARROW_DOWN,Keys.ENTER).perform();
act.sendKeys(Keys.chord(Keys.CONTROL,Keys.TAB)).perform();
}
}