user3013157
user3013157

Reputation: 109

running Selenium webdriver from Python console

This command entered in Python's interpreter opens a new FireFox window:

webdriver.Firefox(executable_path='C:\\...\\geckodriver.exe').get('https://doesnmatter/')

But then when I want to locate elements, but this open another Firefox window:

elements = driver.find_elements_by_xpath("//*doesnmatter")

How do I locate elements in the first Firefox window from Python console?

Upvotes: 1

Views: 86

Answers (1)

shyam
shyam

Reputation: 608

I have recreated your use case and tried a simple solution, First run the below command (assuming you have already imported neccessary libraries)

browser= webdriver.Firefox()

This command will launch a firefox instance. Once you have the "browser" object available, you can perform any action on this instance, for example,

browser.get("http://some_website.com")
ele_of_xpath=browser.find_element_by_xpath("xpath_of_the_element")

In this way you can keep performing activities using command line (in my case it is mac terminal) on the same browser instance.

Upvotes: 1

Related Questions