Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.7k points)

Does anybody know if Selenium (WebDriver preferably) is able to communicate with and act through a browser that is already running before launching a Selenium Client?

I mean if Selenium is able to comunicate with a browser without using the Selenium Server (with could be an Internet Explorer launched manually for example).

1 Answer

0 votes
by (62.9k points)

Extract session_id and _url from driver object

We are taking advantage of the fact that Selenium lets you attach a driver to a session id and a URL. You can extract your session id and _url from the driver object as mentioned below:

session_url = driver.command_executor._url  

session_id = driver.session_id

Tie it up with your framework

In case you are using a framework, you can print out the session id and URL in the method where you try to get the element. In an example shown below, I am using a get_element method which would return the DOM element. I am printing the session id and URL whenever the find_element method fails

def get_element(self,xpath):

        "Return the DOM element of the xpath or 'None' if the element is not found "

        dom_element = None


            dom_element = self.driver.find_element(xpath)

        except Exception,e:


            self.write("Check your locator-'%s"%xpath)

            #Print the session_id and _url in case the element is not found

            self.write("In case you want to reuse session, the session_id and _url for current browser session are: %s,%s"%(driver.session_id ,driver.command_executor._url))


return dom_element

Use the session id and URL

Now you can use the session id and URL, in order to debug the locators. Open python command-line tool and use the below code:

from selenium import webdriver

#Pass the session_url you extracted

driver = webdriver.Remote(command_executor=session_url,desired_capabilities={})

#Attach to the session id you extracted

driver.session_id = session_id

#Resume from that browser state

elm = driver.find_element_by_xpath("xpath") #Perform required action

Hope this helps! 

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium training!

Browse Categories