0

Hi I'm pretty new to selenium and I'm trying to open different links in a for loop but driver.get sends the URL to the bar but without loading. This happens only for the link in the for loop, not the first one. I have tried to look for a couple of similar Qs but I'm not sure what am I doing wrong

    class RunGCTest():
        def test(self):
            driver_location = x
            os.environ["webdriver.chrome.driver"] = driver_location
            driver = webdriver.Chrome(driver_location)
            driver.implicitly_wait(30)
            driver.get("https://test.com/")

                import csv
                with open
                 ....

                for abc in range(len(xyz)):
               
                 driver.get("https://test.com/page="+xyz[abc][1])

ChromeTest = RunGCTest()
ChromeTest.test()
Ryan
  • 129
  • 1
  • 12
  • What's with the prefix `"URL"` in `"URL"+xyz[abc][1]`? –  Jan 19 '21 at 17:39
  • as www.example.com/page=1 page 2 etc So Im just concatenating the page number to the URL – Ryan Jan 19 '21 at 17:46
  • But you're concatenating to a (constant) string `"URL"` when you perhaps meant to prefix with a variable. Please update your code accordingly as the above would obviously not work. –  Jan 19 '21 at 18:01
  • its just a URL with pages and Im concatenating the 1st constant part of the URL with iteration list of the pages numbers – Ryan Jan 19 '21 at 18:30
  • Which get is it failing on? What's the error message? – DMart Jan 19 '21 at 20:29
  • there is no error message, the URL appears in the URL Bar without loading. It loads when I press Enter manually – Ryan Jan 19 '21 at 20:32

1 Answers1

0

I think you have to wait for the page to load completely before looping to the next custom URL. Try out below code snippet:

from selenium.webdriver.support.ui import WebDriverWait
class RunGCTest():

        def wait_for_page_load(self):
            WebDriverWait(self.driver, config.wait).until(
                lambda driver: driver.execute_script('return document.readyState') == 'complete')

        def test(self):
            driver_location = x
            os.environ["webdriver.chrome.driver"] = driver_location
            driver = webdriver.Chrome(driver_location)
            driver.get("http://URL 1/")

                import csv
                with open
                 ....

                for abc in range(len(xyz)):
               
                 driver.get("URL"+xyz[abc][1])
                 wait_for_page_load()

ChromeTest = RunGCTest()
ChromeTest.test()

Hope that this will resolve your query.

Thanks,

Panchdev Singh
  • 121
  • 1
  • 5
  • driver.implicitly_wait(30) Im already doing that but still isn't loading – Ryan Jan 19 '21 at 18:25
  • Could you please double check manually if hitting those custom direct URLs are working as expected first. Because it should work theoretically per the existing code. – Panchdev Singh Jan 19 '21 at 18:30
  • When I press Enter the URL Loads, but Im not sure how Send Enter after driver.get – Ryan Jan 19 '21 at 18:31
  • `driver.get("https://test.com/page="+xyz[abc][1])` Tried that but still not working – Ryan Jan 19 '21 at 18:39
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/227556/discussion-between-panchdev-and-ryan). – Panchdev Singh Jan 19 '21 at 18:44