Reputation: 731
The URL is enter link description here
Is there any way in selenium XPath to get value the element just the element which following sibling of located element
//span[contains(text(),"by")]//following-sibling::a
in this code I want to take the next element because sometimes it is not an anchor tag but span
For getting values of Author I am using the way, searching for "by" word element then
x_authors=driver.find_elements(By.XPATH,'//span[contains(text(),"by")]//following-sibling::a')
x_authors_a=driver.find_elements(By.XPATH,'//span[contains(text(),"by")]//following-sibling::span[1]')
Upvotes: 2
Views: 29316
Reputation: 33361
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:
//span[contains(text(),"by")]
matches more than 16 relevant elements./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.Upvotes: 4