如何使用selenium webdriver使用“CTRL A”从文本字段中选择文本?

时间:2013-07-05 10:21:24

标签: ruby automation selenium-webdriver

我正在使用带有红宝石的selenium 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

1 个答案:

答案 0 :(得分:2)

哼哼..看看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