How to attach the selenium to a existing broswer?

138 views
Skip to first unread message

Zhe Lee

unread,
Nov 29, 2017, 9:17:41 AM11/29/17
to Selenium Users
I search the code on the google but I get the error "The target computer refused to connect due to a positive rejection" Why is that and how to attach selenium to a broswer.

I just want to click some element when I login a website.

# -*- coding: utf-
8 -*- from selenium import webdriver import time import json import traceback import sys import os from urllib import request from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.chrome.options import Options driver = webdriver.Chrome() #python url = driver.command_executor._url #"http://127.0.0.1:60622/hub" print(url) session_id = driver.session_id #'4e167f26-dc1d-4f51-a207-f761eaf73c31' driver = webdriver.Remote(command_executor=url,desired_capabilities={}) driver.session_id = session_id driver.get("http://www.baidu.com")

Evangeline Ireland

unread,
Nov 29, 2017, 11:17:15 AM11/29/17
to Selenium Users
Hi,
Usually work with Ruby and Javascript., But I did notice that you have basically overwritten your first driver instance with the second driver assignment to Remote. 
When using Remote, you need to pass the browser info through the desired capabilities. So you actually don't need driver = webdriver.Chrome().
If you just want to connect to Chrome without using Selenium Grid (or Remote), you don't need the driver=webdriver.Remote.
 Found this site that may make things clearer: https://www.gridlastic.com/python-code-example.html

Hope that helps,
Evangeline
Reply all
Reply to author
Forward
0 new messages