user3013157
user3013157

Reputation: 109

How to understand the webdriver and get() in Selenium?

How to print all html/css tags of a webpage using Selenium:

from selenium import webdriver

browser = webdriver.Firefox()
browser.get('http://seleniumhq.org/')

When I do:

print(browser),

it prints this:

"<selenium.webdriver.firefox.webdriver.WebDriver (session="ce01359c-03e4-499d-a3fb-230bda9ac24c")>"

Is this an Object or variable or a list/set/tuple/dict or what is it? Could someone explain it please?

Upvotes: -1

Views: 144

Answers (3)

undetected Selenium
undetected Selenium

Reputation: 193068

You saw it right. As per the documentation of New Session, the New Session command creates a new WebDriver session with the endpoint node.

HTTP Method     URI Template
POST            /session

As per the remote end steps, the entire process entirely depends up to the implementation , but typically the sessionId, and URL and URL prefix of the upstream remote end are needed to be tracked. Additionally,

  • The session id is the result of generating a UUID.

  • The session be a new session with the session ID of session id.

Hence, browser which is an object of class selenium.webdriver.firefox.webdriver.WebDriver() prints the following:

"<selenium.webdriver.firefox.webdriver.WebDriver (session="ce01359c-03e4-499d-a3fb-230bda9ac24c")>"

You can find a revelant discussion in Values returned by webdrivers

Upvotes: 0

smilechaser
smilechaser

Reputation: 376

You should take a look at the documentation, specifically this page as it gives a good introduction. If you work through that explanation you should get a good (basic) understanding of how the API works. Additional chapters can fill in the gaps about the specifics of locating elements within a page.

On the other hand, if all you're doing is scraping HTML may I suggest you take a look at Beautiful Soup.

Upvotes: 0

Mr. Blue
Mr. Blue

Reputation: 230

The result you're getting is an object. In the beginning of your code you chose to call this object browser (a.k.a assigning it to a variable). When you then run the function browser.get() it will not change the content of the variable browser and therefore the result will have nothing to do with the webpage that you're on.

Upvotes: 3

Related Questions