I have a list with all xpath of links
Here is my code:
original_window = driver.current_window_handle
for stat in stats:
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, stat))).click()
WebDriverWait(driver, 10).until(EC.number_of_windows_to_be(2))
for window_handle in driver.window_handles:
if window_handle != original_window:
driver.switch_to.window(window_handle)
print(driver.current_url)
driver.close()
driver.switch_to.window(original_window)
print(driver.current_url)
break
time.sleep(15)
It works the first time but after that it gives me this error:
https://s5.sir.sportradar.com/sports4africa/fr/1/season/81152/headtohead/322375/90970/match/27122060
https://www.bountou1x2.com/sport.jsp
Traceback (most recent call last):
File "c:\Users\Hama\Documents\Python project\test3.py", line 45, in <module>
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, stat))).click()
File "C:\Users\Hama\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Here is how Stats is defined:
stats = []
for a in driver.find_elements_by_tag_name("tr"):
aa = a.get_attribute("idavv")
if aa is not None:
aaa = "//*[@id=\"simple-row-box-prematch-" + aa + "\"]/td[6]/table/tbody/tr/td[1]"
stats.append(aaa)
if i let only the click event the code works fine like this and opens all windows:
for stat in stats:
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, stat))).click()
time.sleep(15)
The error appears only when i try to switch from the old to new and from the new to old window, it works only the first time
I print the current url just to see if it's switching as it most
Help is appreciated, thanks to all of you
statis not found to be clickable and times out after 10 seconds. Can you include how you have definedstats? Also the HTML of the page you are testing please?aa = a.get_attribute("idavv")-- you are trying to get the value of an attribute calledidavv? I can't find that attribute anywhere on the page. I also can't find any element with an ID likesimple-row-box-prematch. Can you help me figure out exactly which elements you are trying to locate?