Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.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使用驱动程序selenium将焦点从web浏览器切换回终端_Python_Selenium Webdriver - Fatal编程技术网

Python使用驱动程序selenium将焦点从web浏览器切换回终端

Python使用驱动程序selenium将焦点从web浏览器切换回终端,python,selenium-webdriver,Python,Selenium Webdriver,我正在使用SeleniumWebDriver打开一个网页并填写表单 无论如何,在代码的中间,我需要在终端中提供输入数据。 但是焦点仍然停留在webbrowser上,所以我需要手动将鼠标移回终端 是否有办法将焦点从webbrowser切换回终端? 示例代码: import time from selenium import webdriver driver = webdriver.Chrome() # Optional argument, if not specified will searc

我正在使用SeleniumWebDriver打开一个网页并填写表单

无论如何,在代码的中间,我需要在终端

中提供输入数据。 但是焦点仍然停留在webbrowser上,所以我需要手动将鼠标移回终端

是否有办法将焦点从webbrowser切换回终端? 示例代码:

import time
from selenium import webdriver

driver = webdriver.Chrome()  # Optional argument, if not specified will search path.
driver.get('https://www.seleniumeasy.com/test/basic-first-form-demo.html')
search_box = driver.find_element_by_id('user-message')
search_box.send_keys('John Rambo')
time.sleep(5) # Let the user actually see something!
test=input('please provide a number 0-9: \n') # I'd like the focus to switch back to the terminal
driver.quit()

通过Selenium-否。它是一个通过WebDriver协议专门与浏览器通信的库。它只能向浏览器发送请求,浏览器可能会执行请求,也可能不会执行请求

因此,它无法与外界任何东西通信——操作系统及其应用程序切换例程,包括。 为此,您需要一些其他库,这些库可以发出操作系统请求切换应用程序,或者模拟键盘/鼠标输入。但这些都依赖于操作系统,例如Windows、Mac或Linux的不同操作系统