我在使用Python的Selenium工具。
一个小时前,我用了可行的代码,但现在它却返回下面的错误信息:
no such element: Unable to lacate element:...
同样的代码在一小时前还可以运行。
问题出在哪里?我检查了源代码,但它仍然是相同的。
这是我的代码:
import selenium
from selenium import webdriver
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
PATH="C:\Program Files (x86)\chromedriver"
driver=webdriver.Chrome(PATH)
driver.get("https://moitane.ge/shop/5-gudvili/43-axali-xorci-da-xorcproduqti")
time.sleep(3)
#el = driver.find_element(By.XPATH, "//div[@class='style__ShopProductSubCategoryChip-sc-1bc3ssb-2 iKSeHs']")
el = driver.find_element(By.XPATH, "//li[@class='style__CategoryItem-sc-8ncu0g-2 tZtCz']//span[text()='ახალი ხილი']")
time.sleep(3)
el.click()
time.sleep(5)
ell = driver.find_element(By.XPATH, "//*[@id='main-layout']/div[5]/div[4]/div/div[1]/div/div/div/div[1]/div")
这给我报错:
NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='main-layout']/div[5]/div[4]/div/div[1]/div/div/div/div[1]/div"}
(Session info: chrome=89.0.4389.90)
这里是复制的元素:
'<div class="style__ProductItemWrapper-nvyr2y-0 cbyRwl product-item-wrapper"><img class="style__ProductItemImage-nvyr2y-2 gfMqx product-image" src="https://static.moitane.ge/Moitane_files/093c2492-ccf3-4515-adcf-2f610a09e473_Thumb.jpeg" style="width: 166px; height: 132.8px; cursor: pointer;"><p class="style__ProductItemText-nvyr2y-3 ebZGDv" style="cursor: pointer; height: 40px;">香蕉(重量)(进口)</p><div style="display: flex; margin-top: auto; width: 100%; align-items: flex-start;"><span class="style__ProductItemDesc-nvyr2y-4 cIkCnK" style="margin-left: auto;">1 公斤</span></div><div class="style__ProductItemActionsWrapper-nvyr2y-5 kQtpVm" style="cursor: pointer; position: relative;"><span class="style__ProductItemPrice-nvyr2y-6 hLsuWS"><span>4.10 ₾</span> </span><div style="position: absolute; top: 0px; right: 0px; height: 100%; width: 50%;"></div><span class="style__ProductItemActionButton-nvyr2y-7 bieLnj"><i class="icon-plus" style="color: rgb(146, 146, 157);"></i></span></div></div>
'