def checker():
try:
ispresent = driver.find_element(by=By.XPATH, value=xpaths) #ispresent = driver.find_element_by_xpath(xpaths) #works fine
except:
time.sleep(2)
openlink()
else:
buyandlog()
如果xpath存在,则没有问题,如果我使用没有xpath的链接,则except不会运行,终端上没有发现错误;如果我尝试在except下输入print("something"),那么它不会打印任何东西,也不会在vscode下的输出部分打印,也不会在终端
中打印。I fixed it
ispresent = driver.find_element(By.CLASS_NAME, "a-button-text.place.your-order-button").send_keys("webdriver" + Keys.ENTER)
添加.send_keys("webdriver"+ Keys.ENTER)将引发错误,然后使except工作
尝试:
from selenium.common.exceptions import NoSuchElementException
def checker():
try:
link = driver.find_element_by_xpath(linkAddress)
except NoSuchElementException:
time.sleep(2)