How do I use .get in Selenium? Python

1

I'm doing a program and I need to open a web page from python, I'm using the selenium module. This is the code:

from selenium import webdriver
browser=webdriver.Chrome
browser.get("https://facebook.com")

The problem is that when I try it, I see this error in the console:

TypeError: get() missing 1 required positional argument: 'url'

But according to me if I'm putting the URL argument. What do I need?

    
asked by Sebastian Mora 06.12.2018 в 22:17
source

1 answer

1

When initializing browser you missed the parentheses after the name of the class, that is, it should be like this:

browser=webdriver.Chrome()

In this way an object is created, and the variable browser would be a reference to that new created object.

As you had it, instead:

browser=webdriver.Chrome

the variable browser would be a reference to the class , instead of being an object, so it could not work correctly since there is no properly initialized object.

As for explaining the strange error that told you that the url was missing, when clearly you were passing it, it is due to the following. When you tried to invoke the browser.get() method, since browser referenced a class instead of an object, you were not invoking an object method, but a method of the class. In the classes the methods are declared with a first extra parameter, self , that when you invoke through a Python object it fills up automatically. In this case, however, when invoking it through the class, Python expected two parameters, self and url and only passed one, so the error told you that the second was missing.

    
answered by 07.12.2018 / 00:08
source