[Python] How do I parameterize a list of URL's for Selenium tests using PyTest?

Discussão em 'Python' iniciado por Stack, Julho 2, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to automate disabling subscriptions for 100 stores on a website. I have clicked this together once in Firefox and now I need help on how to have Selenium loop through the steps while loading the next URL from a text file. How do I do this?

    I can export the script from Selenium but I see no way to import it once the necessary changes to the code have been made. This is the script:

    # Generated by Selenium IDE
    import pytest
    import time
    import json
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.action_chains import ActionChains
    from selenium.webdriver.support import expected_conditions
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

    class TestFRS():
    def setup_method(self, method):
    self.driver = webdriver.Firefox()
    self.vars = {}

    def teardown_method(self, method):
    self.driver.quit()

    def test_fRS(self):
    self.driver.get("https://my.urls.that.should.be.loaded.from.urls.txt")
    self.driver.set_window_size(2576, 1408)
    self.vars["root"] = self.driver.current_window_handle
    self.driver.switch_to.window(self.vars["win3657"])
    self.driver.find_element(By.CSS_SELECTOR, "li:nth-child(3) div:nth-child(2)").click()
    self.driver.find_element(By.LINK_TEXT, "Edit").click()
    self.driver.find_element(By.CSS_SELECTOR, ".radio-square-option:nth-child(2) .x-checklist__span").click()
    self.driver.find_element(By.CSS_SELECTOR, ".btn").click()
    self.driver.close()
    self.driver.switch_to.window(self.vars["root"])


    How do I make this load urls.txt, loop as often as there are entries (one per line) in the file, and load it into Selenium in Firefox? TIA!

    Continue reading...

Compartilhe esta Página