Home > Back-end >  xpath selenium locating next sibling - any element
xpath selenium locating next sibling - any element

Time:11-02

The URL is enter image description here

enter image description here

CodePudding user response:

The following XPath will give exactly what you need:

"//span[text()='by ']/following-sibling::*[1]"

There are several points to be improved in your initial XPath:

  1. //span[contains(text(),"by")] matches more than 16 relevant elements.
  2. /following-sibling::* selects All the following siblings, of any tag name. But this selects all the following siblings, not only adjacent following siblings. To make this precise [1] index added.
  • Related