Webdriver not error but also does not open the browser

Asked

Viewed 167 times

0

I tested a simple code to make the webdriver open Chrome, and was successfully executed, but the code below not error, but does not open the browser.

from selenium.webdriver.common.keys import Keys
import time


class InstagramBOT:
 def _init_(self, username, password):
     self.username = username
     self.password = password
     self.driver = webdriver.Chrome(executable_path=r'C:\Program Files (x86)\chromedriver.exe')


def login(self):
 driver = self.driver
 driver.get('https://www.instagram.com/')

 Raphaelbot = InstagramBOT('***', '***')
 raphaelbot.login()
  • look at the webdriver version on your pc

  • The path is correct?

  • What is the error message?

1 answer

-1

I already faced this same error, try installing the webdriver in a variable with that lib from webdriver_manager.chrome import ChromeDriverManager

Your code will look like this:

from selenium.webdriver.common.keys import Keys
import time

#CASO NÃO TENHA A LIB, IRÁ BAIXAR A LIB ATRAVÉS DO PIP E IMPORTARÁ
#USE ESSE TRY/EXCEPT NO PRIMEIRO USO, DEPOIS NÃO É MAIS NECESSÁRIO
#OU UTILIZE O TERMINAL PARA INSTALAR A LIB E PODE IMPORTAR NORMALMENTE
import os
try:
    from webdriver_manager.chrome import ChromeDriverManager
except:
    os.system("pip install webdriver-manager")
    from webdriver_manager.chrome import ChromeDriverManager


_webdriver=ChromeDriverManager().install() 

class InstagramBOT:
 def _init_(self, username, password):
     self.username = username
     self.password = password
     self.driver = webdriver.Chrome(_webdriver)


def login(self):
 driver = self.driver
 driver.get('https://www.instagram.com/')

 Raphaelbot = InstagramBOT('***', '***')
 raphaelbot.login()

My operating system is Linux, if it is Windows yours, search how to use this lib webdriver-maneger if there is an error in the execution. But I believe it will work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.