Why is my exception not kicking in and catching the error. I know it cant go up to 35 because there is no 35, but it should peform my exception if this is the case or not? Thanks for answares in advance.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(options=options)
website = "https://langerball.de/"
driver.get(website)
land = "DEUTSCHLAND"
x = driver.find_element(By.XPATH, "(//a[(text()='%s')])" %land)
x.click()
def maxspieltag():
i = 1
while i in range(100):
xpath_t = ("//b[text()='%s']" %i)
try:
driver.find_element(By.XPATH, xpath_t)
except NoSuchElementException:
i -= 1
break
i +=1
return i
print(maxspieltag())
I added a picture because it worked before now it does not want to and for better explenation: