1

Here is my code.

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from bs4 import BeautifulSoup
import time
from time import sleep
browser = webdriver.Chrome("C:/Utility/chromedriver.exe")

wait = WebDriverWait(browser, 5)

web = Browser()
url = 'https://www_corp_site/admin/?page=0'
web.go_to(url)

web.type('first.last@gmail.com', into='username')
web.click('Next')
# Wait for 2 seconds
time.sleep(1)

# password
web.type('pswd', into='Password')
web.click('Next')
time.sleep(1)

element = browser.find_element_by_id('main_content')
print(element.text)

For some reason two Chrome browsers are opening, and I'm getting this error:

WebDriverException: chrome not reachable
  (Session info: chrome=69.0.3497.100)
  (Driver info: chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.17134 x86_64)

How can I open one single browser, reference that one, and print all data from the 'main_content' ID? Or, table ID = 'dags'?

enter image description here

ASH
  • 20,759
  • 19
  • 87
  • 200
  • 1
    Possible duplicate of https://stackoverflow.com/questions/45688020/chrome-not-reachable-selenium-webdriver-error , is there anything in that ask that helps, or have you checked those solutions already? – G. Anderson Sep 27 '18 at 14:48

1 Answers1

4

You're calling webdriver.Chrome() and Browser(). I don't know what Browser() is, but it appears to be opening another instance of chrome. So, when you define the variable browser and the variable web you're getting a Chrome instance for each of them. Try this:

browser = webdriver.Chrome("C:/Utility/chromedriver.exe")

wait = WebDriverWait(browser, 5)

url = 'https://www_corp_site/admin/?page=0'
browser.get(url)

browser.find_element_by_id('username').type('first.last@gmail.com')
browser.find_element_by_id('Next').click()
# Instead of sleeping, use Selenium's wait feature to proceed as soon as the element is available
WebDriverWait(browser, 5).until(EC.presence_of_element_located((By.ID, 'Password')))

# password
browser.find_element_by_id('Password').type('pswd')
browser.find_element_by_id('Next').click()
WebDriverWait(browser, 5).until(EC.presence_of_element_located((By.ID, 'main_content')))

element = browser.find_element_by_id('main_content')
print(element.text)

I'm not sure if those are IDs of elements, so you might have to change those.

Michael Cox
  • 1,116
  • 2
  • 11
  • 22