How to copy text with selenium xpath? When I writing
driver.find_elements_by_xpath("//div[@class='rankingItem-value js-countable']").text I get next error:
Traceback (most recent call last): File "<stdin>", line 15, in <module> AttributeError: 'list' object has no attribute 'text' full code:
from selenium import webdriver from selenium.webdriver.common.keys import Keys import time driver = webdriver.Firefox() driver.get('https://www.similarweb.com/') driver.find_element_by_id("js-swSearch-input").send_keys("www.pornhub.com") driver.find_element_by_css_selector("button.swSearch-submit").click() #self.driver.implicitly_wait(30) time.sleep(10) content = driver.find_elements_by_xpath("//div[@class='rankingItem-value js-countable']").text print(content) I need to copy site's global rank to a table, "22" one. How?
find_elements_by_xpathreturns a list of elements. You have to iterate the elements and retrieve the text from each element.