我使用硒的webdriver红宝石。
clc = WAIT.until { driver.find_element(:id, 'embed-showembedcode') }
driver.action.key_down(:control).click(clc).send_keys("a").key_up(:control).perform
这是我现在用的,但我得到一个错误..
{"testcase":"load: should check embed code","message":"erro
r - Cannot perform native interaction: Could not load native events component. \
n [\"[remote server] file:///C:/Users/nachiket/AppData/Local/Temp/webdriver-prof
ile20130705-5880-g873k8/extensions/fxdriver@googlecode.com/components/driver_com
ponent.js:8738:in `generateErrorForNativeEvents'\", \"[remote server] file:///C:
/Users/nachiket/AppData/Local/Temp/webdriver-profile20130705-5880-g873k8/extensi
ons/fxdriver@googlecode.com/components/driver_component.js:8771:in `FirefoxDrive
赫姆再看看Selenium::WebDriver::Element#text
因此,使用:
elem = wait.until {
element = driver.find_element(:id, 'embed-showembedcode')
element if element.displayed?
}
puts elem.text # => target text will be printed here
现在修正这个错误,我建议你总是做一些机器表示测试如下。 这不是需要的Selenium::WebDriver::Keys
提到的映射将是很好的在你的机器的工作:
require "selenium-webdriver"
puts Selenium::WebDriver::Keys::KEYS
# => {:null=>"\uE000", :cancel=>"\uE001", :help=>"\uE002", :backspace=>"\uE003", :tab=>"\uE004",
# :clear=>"\uE005", :return=>"\uE006",:enter=>"\uE007", :shift=>"\uE008",
# :left_shift=>"\uE008", :control=>"\uE009",.. }
elem = wait.until {
element = driver.find_element(:id, 'embed-showembedcode')
element if element.displayed?
}
driver.action.key_down("\uE009").click(elem).send_keys("a").key_up("\uE009").perform
文章来源: How do i select text from a text field using 'CTRL A ' using selenium webdriver?