Issue
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]')
Solution
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.
Answered By - Prophet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.