Loop through all clickable links selenium Python


I’m trying to click each job listing by looping through each one. How can I get to a previous state after I click the link and then click the next link? I tried driver.back(), here I tried driver.get(url) but nothing works. Any help would be appreciated.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from selenium.common.exceptions import NoSuchElementException
import csv
import re
import requests
from bs4 import BeautifulSoup

driver_service = Service(executable_path="C:Program Files (x86)chromedriver.exe")
driver = webdriver.Chrome(service=driver_service)
driver.maximize_window()  # load web driver
wait = WebDriverWait(driver, 5)

looking_job = driver.find_elements(By.XPATH, "//a[@data-automation='jobTitle']")
e = []
count = 1
for xx in looking_job:
    get_url = ""
    get_url += driver.current_url

    second = xx.find_element(By.XPATH, "(//a[@data-automation='jobTitle'])[{}]".format(count)).click()
    count += 1
Asked By: jhgjhgkk



looking_job = [x.get_attribute('href') for x in driver.find_elements(By.XPATH, "//a[@data-automation='jobTitle']")]
for job in looking_job:

Just grab all the links and driver.get to them.

Answered By: Arundeep Chohan
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.