2

I want to print this part to the console. (marked) Image

This is my last try:

I get this error with my last try:

Unable to locate element:

{"method":"xpath","selector":"//*[@id="react-root"]/section/main/div/ul/li[2]/a/span"}

Keep in my this text changes.

followers = driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/ul/li[2]/a/span').GetAttribute("innerHTML")

print("Followers: " + followers)
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
Zetlex DK
  • 23
  • 4

2 Answers2

2

You can use the below xpath :

//a[contains(@href, 'followers')]/span

and there isn't any GetAttribute method available in Selenium - Python binding.

Instead you can use :

followers = driver.find_element_by_xpath("//a[contains(@href, 'followers')]/span").get_attribute("innerHTML")
print("Followers: ", followers)
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
0

Can you check this

followerTxt=driver.find_element_by_xpath("((//a[@class='-nal3 ']/span)[2])")

print("Total followers: ",followerTxt.text)

I've check based on the element index

enter image description here

This is my Output

YaDav MaNish
  • 1,260
  • 2
  • 12
  • 20