Accessing A Webelement Within A List Of Webelement In Selenium Using Pything
I have the following HTML
My First Headin
Solution 1:
You can try this :
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
url2 = 'C:\\Users\\ed821\\Downloads\\TEST2.html'
driver = webdriver.Chrome()
driver.get(url2)
titles = driver.find_elements_by_class_name("pp")
for title in titles:
heading = title.find_element_by_tag_name("h1")
print("Title is:" + heading.text)
You are trying to search h1
by class name but h1
is tag name!
You can learn more about find_element_by_tag_name
from here
And you can learn more about other find_element_by_<>
functions from official documentation.
Post a Comment for "Accessing A Webelement Within A List Of Webelement In Selenium Using Pything"