简体   繁体   中英

Send key stroke to chromedriver, using selenium python

I am planning to use keyboard shortcuts to drive chromedriver; although I can't find a suitable example.

I load chromedriver as driver.remote object in selenium python; so I can access the elements, and so far it works fine; I can send keys to an element.

Although I do not see how you can actually send browser shortcuts though; the driver.remote does not have a sendkey function; just the elements has it.

So if I want to open a menu shortcut to do any action, I can't. Is there a way to do so, or it is out of the scope of Selenium per se?

You cannot use key combinations with chromedriver , but you can try some approaches to perform required actions:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('/path/to/your/local/file.html') # To load page
with open('/path/to/your/local/file.html', 'w') as f:
    f.write(driver.page_source) # To save currently opened page HTML source code to local file
driver.execute_script('window.open('https://google.com', 'new');') # To open Google page in new tab/window

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM