[英]Is there any possible way to get image "src" from find_elements_by_class it just all returning None
I get 250 Total results.我得到 250 个总结果。 I tried to get 10 of the first result's image src but all return None.我试图获取第一个结果的图像 src 中的 10 个,但都返回 None。 If i switch to use XPATH it can't be done automatically because there are too many of them to be manually selected.如果我切换到使用 XPATH 它不能自动完成,因为它们太多需要手动选择。
historylist = WebDriverWait(driver, 100).until(
EC.presence_of_all_elements_located((By.CLASS_NAME, "coinflip-list__item.coinflip-history-list__item")))
print(f"Total {len(historylist)}")
for x in range(10):
print(historylist[x].get_attribute("src"))
Total 250 Printing out first 10: <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="7bb1f785-409c-42c8-a85e-b6a7abd9d7be")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="4c445a89-003a-4e42-95b5-4dd0648d3a99")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="a0d21128-055d-4320-aae1-f1bebb532c2d")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="7606d8a6-332b-4584-932f-da0a8203918b")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="619896b8-b79d-4dba-b130-869a758402f7")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="d20d2480-b7e8-49e3-a66d-127c021d133e")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="4a6088总共 250 打印出前 10 个: <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="7bb1f785-409c-42c8-a85e-b6a7abd9d7be")> <selenium.webdriver.remote.webelement.WebElement ( session="d6ac99726310ff2fc4b6070ea0ab7fec", element="4c445a89-003a-4e42-95b5-4dd0648d3a99")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="a0d21128-055d-4320-aae1-f1bebb532c2d ")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="7606d8a6-332b-4584-932f-da0a8203918b")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac9972630abfec2 ", element="619896b8-b79d-4dba-b130-869a758402f7")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="d20d2480-b7e8-49e3-a66d-127c021d3e")> selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="4a6088 9a-58a4-4a77-a033-9303b001fbfa")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="0514a847-0571-4415-b6e6-d9cb96294525")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="8b150b8f-31ec-4090-b983-6a5992f97e41")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="7f909f2d-3459-47ba-9520-04979d958ddd")> 9a-58a4-4a77-a033-9303b001fbfa")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="0514a847-0571-4415-b6e6-d9cb96294525".webdriver.mote .webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="8b150b8f-31ec-4090-b983-6a5992f97e41")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0b7fe" 47ba-9520-04979d958ddd")>
That's the output.那是 output。
It looks like your use of By.CLASS_NAME
is incorrect.您对By.CLASS_NAME
的使用似乎不正确。 Here这里
historylist = WebDriverWait(driver, 100).until(
EC.presence_of_all_elements_located((By.CLASS_NAME, "coinflip-list__item.coinflip-history-list__item")))
CLASS_NAME
or find_element_by_class_name
or find_elements_by_class_name
accepts only a single class. CLASS_NAME
或find_element_by_class_name
或find_elements_by_class_name
仅接受单个 class。 Compound classes are not working.复合类不起作用。
Change it to By.CSS_SELECTOR
:将其更改为By.CSS_SELECTOR
:
historylist = WebDriverWait(driver, 100).until(
EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".coinflip-list__item.coinflip-history-list__item")))
Where coinflip-list__item
and coinflip-history-list__item
are class names in a single html tag.其中coinflip-list__item
和coinflip-history-list__item
是单个 html 标签中的 class 名称。
Check here for description: https://selenium-python.readthedocs.io/locating-elements.html#locating-elements-by-class-name .在这里查看描述: https://selenium-python.readthedocs.io/locating-elements.html#locating-elements-by-class-name 。
Second , try using visibility_of_all_elements_located
instead of presence_of_all_elements_located
.其次,尝试使用visibility_of_all_elements_located
而不是presence_of_all_elements_located
。
Other than that, check that your locator is correct.除此之外,请检查您的定位器是否正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.