Reputation: 43
I have a problem with extracting the hashtags from a selected photo
the code I'm workin now is
<a class=" abcd" href="/explore/tags/ht1/" tabindex="0">#ht1</a>
<a class=" abcd" href="/explore/tags/ht2/" tabindex="0">#ht2</a>
<a class=" abcd" href="/explore/tags/ht3/" tabindex="0">#ht3</a>
<a class=" abcd" href="/explore/tags/ht4/" tabindex="0">#ht4</a>
So I need to place them on a list, so I write
tags = driver.find_elements_by_class_name('abcd')
And that works, I can actually can print the list and check for the exact number of Ht
But when I do
tags[0].text
Only executes a white line and I need to print "#ht1" I tested that with other single classes and it worked, I'm thinking that the problem is about printing a list.
Upvotes: 0
Views: 372
Reputation: 9969
You might need to wait for the page to load and the elements to become visibile.
tags = driver.find_elements_by_class_name('abcd')
replace with
WebDriverWait(driver, 10).until(EC.visibility_of_all_elements_located((By.CLASS_NAME,"abcd")))
imports
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Upvotes: 2