嗨,我有这个代码,它从这个元素中获取文本但由于它的web元素,我无法将它附加到列表中,也无法循环使用它。
这是我的代码
import selenium
import os
from tkinter import *
from tkinter import filedialog
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium import webdriver
from selenium import webdriver
import contextlib as textmanager
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
PATH= "C:chromedriverschromedriver.exe"
driver= webdriver.Chrome(PATH)
driver.get("https://typetest.io/")
textt= driver.find_element_by_class_name("test-word")
for items in textt:
print(items.text)
这是输出
Traceback (most recent call last):
File "c:Usersramhelsinkiprojectsselenium typtest.io .py", line 26, in <module>
for items in textt:
TypeError: 'WebElement' object is not iterable
像这样使用elements
而不是element
-
textt = driver.find_elements_by_class_name("test-word")