Fails to open a link in Python using Selenium Webdriver

0 votes

I have this code, it gets a link, opens it, gets the image, downloads it to my desktop and then goes to the next link of the list. But when it goes to the next link it doesn't "press enter" in the navigator, it puts the link there but it doesn't go to the next website.

How to fix it?

time.sleep(1) 

lines = [line.rstrip('\n') for line in open("C:/Users/Luís/Desktop/PEBTXT/linkdasimagens.txt")]

x = 0

 

while True:

    try:        

        time.sleep(3)

        y = lines[x]

        driver.get(y)

 

        ###Pegar imagem

 

        img = driver.find_element_by_xpath("//img[@class='BRnoselect']")

        src = img.get_attribute('src')

        with open(("C:/Users/Luís/Desktop/PEBTXT/file{}.jpg".format(x)), "wb") as f:

            f.write(requests.get(src).content)

        print(x)

        x += 1

        print(x)

    except NoSuchElementException:

        pass

EDIT: Solution for the problem, I add driver.get again to "press the enter"

    time.sleep(2)

    y = lines[x]

    driver.get(y)

    time.sleep(1)

    driver.get(y) 
Jul 30, 2018 in Selenium by Martin
• 4,210 points
47 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
Try resetting value of y. Put y="" after the x += 1
answered Jul 30, 2018 by Samarpit
• 5,130 points

Related Questions In Selenium

0 votes
5 answers
0 votes
2 answers

Is it possible to scroll down in a webpage using selenium webdriver programmed on python?

I using next code for facebook for ...READ MORE

answered 4 days ago in Selenium by mslavikas@gmail.com
4,184 views
0 votes
1 answer

I tried to open a new website when a new tab is opened using Selenium Webdriver

Try this code: ArrayList<String> tabs = new ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,030 points
456 views
0 votes
1 answer

How can we use Selenium with Python?

First  Install Python based on the Operating ...READ MORE

answered May 7, 2018 in Selenium by Meci Matt
• 9,400 points
37 views
0 votes
1 answer

How to open a browser window in full screen using Selenium WebDriver with C#

Simply Use this: driver.Manage().Window.Maximize(); READ MORE

answered Jun 7, 2018 in Selenium by Samarpit
• 5,130 points
1,832 views
0 votes
1 answer

How to get HTML Source of WebElement in Selenium WebDriver using Python?

You can read innerHTML attribute to get source of ...READ MORE

answered Jun 13, 2018 in Selenium by Samarpit
• 5,130 points
7,630 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.