P
P
Pavel Ryabov2019-09-14 09:26:05
Python
Pavel Ryabov, 2019-09-14 09:26:05

Click all links on a page?

There is this code:

def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get('https://yandex.ru')

    def test_01(self):
        # def links_parse(self):
            driver = self.driver
            driver.fullscreen_window()
            links = []
            links = driver.find_elements_by_xpath("//*[contains(@href, 'http')]")

        # def clicking(self, links):
            for link in links:
                link.click()
                driver.get('https://yandex.ru')
                time.sleep(4)    

    def tearDown(self):
        self.driver.quit()

It should fill the links array with links and then loop through them to return to the main page.
The first link is clicked, it returns to the main page, but when you click on the next one, it crashes. And in the console "element not interactable". At the same time, if you pick links manually from the array, then some will be clicked, and some will be "not interactable" in the same way. Tell me, please, if I have only links in the array, how can they be "not interactable" and how to solve this problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2019-09-14
@dimonchik2013

how can they be "not interactable"

in our time, anything can happen, but
you click like a proper kid - you go back, you load, you find, you click?
or as a noob who has stacked the code?

V
Val1n0r, 2019-09-14
@devildayne

So it's possible

for link in links:
                link.click()
                driver.back()
                time.sleep(4)

If you just need to open the link and return to yandex.ru (driver.back())
And so, as it seems to me, you need to check whether Selenium parses links correctly
and click them through the indexes in a loop (looking at the result in the browser along the way)
you can wait until the heap full page load if needed
from selenium.webdriver.support.ui import WebDriverWait 

WebDriverWait(driver, 100).until(
                    EC.element_to_be_clickable((By.XPATH, "//input[contains(@value,'Назад')]")))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question