Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I am trying to retrieve the data from the webpage has the HTML in below

 <div class="someclass">

       <p class="name"><a href="#/word/1/">helloworld</a></p>

       </div>

My goal is to parse "#/word/1/" What I did is

  target = self.driver.find_element_by_class_name('someclass')

        print target

        print target.text

        print target.get_attribute("css=a@href")

        print target.tag_name

but the output is:

 <selenium.webdriver.remote.webelement.WebElement object at 0x10bf16210>

 helloworld

 None

 div 

I tried so many ways, it seems there is no way I can get the content of 'a href' within the targeted class.

I really don't want to do is get the source code of the page, and then do a string searching, that seems dumb.

any way to get that?

1 Answer

0 votes
by (62.9k points)

Use the below code:

self.driver.find_element_by_css_selector('.someclass a').get_attribute('href')

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium certification

Browse Categories

...