如何在::before 和::after 之间获取值?
How to get value between ::before & ::after?
我想从 selenium 中的 ::before ::after 之间的文本中获取值。我想用xpath做是不可能的,我可以用什么JSexecutor代码?
我想得到的值:
::before
和 ::after
是 css 并且不是可打印的文本。因此,要打印文本 Widget,您可以使用以下任一方法 :
使用css选择器:
System.out.println(wd.findElement(By.cssSelector("div.linkbox.margin-bottom-20 > h1.heading")).getText());
使用 xpath:
System.out.println(wd.findElement(By.xpath("//div[@class='linkbox margin-bottom-20']/h1[@class='heading']")).getText());
理想情况下,要提取文本 Some Text,因为该元素是动态元素,您必须为 [=] 引入 16=] 并且您可以使用以下任一项 :
使用css选择器:
System.out.println(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.linkbox.margin-bottom-20 > h1.heading"))).getText());
使用 xpath:
System.out.println(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='linkbox margin-bottom-20']/h1[@class='heading']"))).getText());
我想从 selenium 中的 ::before ::after 之间的文本中获取值。我想用xpath做是不可能的,我可以用什么JSexecutor代码?
我想得到的值:
::before
和 ::after
是 css 并且不是可打印的文本。因此,要打印文本 Widget,您可以使用以下任一方法
使用css选择器:
System.out.println(wd.findElement(By.cssSelector("div.linkbox.margin-bottom-20 > h1.heading")).getText());
使用 xpath:
System.out.println(wd.findElement(By.xpath("//div[@class='linkbox margin-bottom-20']/h1[@class='heading']")).getText());
理想情况下,要提取文本 Some Text,因为该元素是动态元素,您必须为 [=] 引入
使用css选择器:
System.out.println(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.linkbox.margin-bottom-20 > h1.heading"))).getText());
使用 xpath:
System.out.println(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='linkbox margin-bottom-20']/h1[@class='heading']"))).getText());