Let's say all Author/username elements in one webpage look like this... How can I get to the href part using python and Selenium? users = browser.find_elements_by_xpath(?)
<span>
Author:
<a href="/account/57608-bob">
bob
</a>
</span>
Thanks.
Use the querySelector() method to get an element by an href attribute, e.g. document. querySelector('a[href="https://example.com"]') . The method returns the first element that matches the selector or null if no element with the provided selector exists in the DOM.
Selenium Web DriverAutomation TestingSoftware Testing. We can click on a link on page with the help of locators available in Selenium. Link text and partial link text are the locators generally used for clicking links. Both these locators work with the text available inside the anchor tags.
Use find_elements_by_tag_name('a')
to find the 'a' tags, and then use get_attribute('href')
to get the link string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With