将密钥发送给硒,而不是发送给element [英] Send keys not to element but in general selenium

查看:76
本文介绍了将密钥发送给硒,而不是发送给element的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我要send_keys(Keys.LEFT_CONTROL + 't') 现在,我要在页面上找到任何元素

I want to send_keys(Keys.LEFT_CONTROL + 't') Now to do this I locate any element on the page

elem = self.browser.find_element_by_name('body')
elem.send_keys(Keys.LEFT_CONTROL + 't')

问题是,每次我想发送以上键时,我都必须找到一些我实际上不感兴趣的元素.

Problem is that each time I want to send above keys I have to locate some element, which actually I'm not interested in.

我该如何一般地而不是页面的特定对象发送密钥,我想要类似self.browser.send_keys(Keys.LEFT_CONTROL + 't')的东西?甚至有可能吗?

How can I send keys generally and not to specific object of page, I want something like self.browser.send_keys(Keys.LEFT_CONTROL + 't')? Is it even possible?

推荐答案

您正在使用WebDriver与页面上的实际元素进行交互.它不起作用.

You are using WebDriver to interact with the actual elements on the page. It will not work.

尝试使用操作

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys

actions = ActionChains(driver)
actions.send_keys(Keys.LEFT_CONTROL + 't')
actions.perform()

请参阅文档: http://selenium-python.readthedocs .io/api.html?highlight = send_keys#module-selenium.webdriver.common.action_chains

这篇关于将密钥发送给硒,而不是发送给element的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆