2

i have just started selenium coding. i have python 3.6.6, executing following code on jupyter notebook (with chrome broser)

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

driver = webdriver.Ie("C:\\Python 36\\IEDriverServer.exe")
driver.get('https://google.com')

print(driver.title)
print(driver.page_source)
driver.close()

this is giving following output:

WebDriver WebDriverThis is the initial start page for the WebDriver server.

In this process an IE browser gets open and goes to google.com (any desired site) but not getting closed

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
omkar patil
  • 53
  • 1
  • 1
  • 10
  • It might be a timing issue. The page is not fully loaded and the title is not set when you're trying to get the title. You could apply [WebDriverWait](https://selenium-python.readthedocs.io/waits.html#explicit-waits) to wait for the page title to render. – Yu Zhou Feb 17 '20 at 04:13

1 Answers1

0

To extract the Page Titile and the Page Source you need to:

  • Invoke the FQDN i.e https://www.google.com/ through get(), i.e. including www.
  • Induce WebDriverWait for a clickable WebElement to be interactive.
  • While ending your program invoke quit() instead of close().
  • You can use the following solution:

    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
    driver = webdriver.Ie("C:\\Python 36\\IEDriverServer.exe")
    driver.get('https://www.google.com/')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "q")))
    print(driver.title)
    print(driver.page_source)
    driver.quit()
    
Yu Zhou
  • 11,532
  • 1
  • 8
  • 22
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352