running Selenium webdriver from Python console
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?
1 Answer
1
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.
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
thnx, seems to be working :)
– user3013157
Sep 11 '18 at 10:43