Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Python控制台运行SeleniumWebDriver_Python_Selenium Webdriver_Firefox - Fatal编程技术网

从Python控制台运行SeleniumWebDriver

从Python控制台运行SeleniumWebDriver,python,selenium-webdriver,firefox,Python,Selenium Webdriver,Firefox,在Python解释器中输入此命令将打开一个新的FireFox窗口: webdriver.Firefox(executable_path='C:\\...\\geckodriver.exe').get('https://doesnmatter/') elements = driver.find_elements_by_xpath("//*doesnmatter") 但当我想定位元素时,这会打开另一个Firefox窗口: webdriver.Firefox(executable_path='C:

在Python解释器中输入此命令将打开一个新的FireFox窗口:

webdriver.Firefox(executable_path='C:\\...\\geckodriver.exe').get('https://doesnmatter/')
elements = driver.find_elements_by_xpath("//*doesnmatter")
但当我想定位元素时,这会打开另一个Firefox窗口:

webdriver.Firefox(executable_path='C:\\...\\geckodriver.exe').get('https://doesnmatter/')
elements = driver.find_elements_by_xpath("//*doesnmatter")

如何在Python控制台的第一个Firefox窗口中定位元素?

我已经重新创建了您的用例,并尝试了一个简单的解决方案, 首先运行下面的命令(假设您已经导入了必要的库)

此命令将启动firefox实例。一旦“浏览器”对象可用,就可以在此实例上执行任何操作,例如

browser.get("http://some_website.com")
ele_of_xpath=browser.find_element_by_xpath("xpath_of_the_element")
通过这种方式,您可以在同一浏览器实例上使用命令行(在我的示例中是mac终端)继续执行活动