1 year ago

#383871

test-img

Ahmed Bahusain

Python Selenium driver.back() stops loop raise exception inside a loop

When I use an iterator over a list in python, and I click a link and go back to the parent page using driver.back, the loop variable becomes undefined , and the loop stops after first iteration and raises exception

Any tips to solve this issue

See the code below:

from selenium import  webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome("/Users/ahmed/Desktop/mixes/chromedriver.exe")
url  = 'https://www.premierleague.com/players'
divs = main2.find_elements(by = By.TAG_NAME, value="tr")
print(divs.__sizeof__())
for i in divs :
    print(i.text)
    link = i.find_element(by= By.TAG_NAME, value="a")
    link.click()
    club = driver.find_element(by= By.CLASS_NAME,value= "team")
    print(club.text)
    driver.back()

python

selenium

selenium-chromedriver

web-crawler

0 Answers

Your Answer

Accepted video resources