Sunday, October 5, 2025

python – Discovering sibling of discovered aspect utilizing selenium


I’ve bought a area with a date in it that is recognized by a code that is proven within the div earlier to it.


09.01.2020

All the category names are generic and seem many occasions, however I can discover the div class containing the code I am after (123) through the use of

aspect = browser.find_element_by_xpath("//div[contains(text(),'151')]")

and might discover the dad or mum utilizing

dad or mum = aspect.find_element_by_xpath("..")

However I am not caught on discover the date within the subsequent aspect (which is what I am after). The following aspect is , I suppose, the next sibling of the dad or mum. There’s a ‘following_sibling’ technique like that will get you the sibling of one thing in your xpath, like this:

browser.find_elements_by_xpath("//div[contains(text(),'(123)')]/following-sibling::div")

however that after all will get me the fcodeText aspect, not what I am after – I blv. I want one thing within the type of

dad or mum.find_element_by_xpath("following_sibling") 

since I am looking out based mostly on a component and never looking out the entire doc for the sibling following a given little bit of textual content. I do not appear to seek out any docs on the usage of “..” for locating a dad or mum, but when I might it may need data on a similar technique for sibling as a substitute of dad or mum.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

PHP Code Snippets Powered By : XYZScripts.com