Ruby的新手问题

时间:2018-03-23 04:08:14

标签: ruby

尝试加快我的航空公司办理登机手续。

require "selenium-webdriver"
Selenium::WebDriver::Firefox::Binary.path='C:\Program Files (x86)\Firefox 
Developer Edition\firefox.exe'

driver = Selenium::WebDriver.for :firefox
driver.navigate.to "https://checkin.westjet.com/"
sleep(1)

first_name = driver.find_element(id: 'firstName')
first_name.click
first_name.send_keys ('Test')

last_name = driver.find_element(id: 'lastName')
last_name.click
last_name.send_keys('Test')

pnr = driver.find_element(id: 'recordLocator')
pnr.click
pnr.send_keys('ABC123')

当我运行程序时,Firefox启动,我可以看到点击进入firstName字段,因为光标在那里,但是send_keys没有在字段中添加任何内容。命令提示符的输出显示:

C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/selenium-webdriver- 
3.11.0/lib/selenium/webdriver/remote/response.rb:72:in `assert_ok': status 
code 400 (Selenium::WebDriver::Error::ServerError)
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/remote/response.rb:32:in `initialize'
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/remote/http/common.rb:81:in `new'
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/remote/http/common.rb:81:in `create_response'
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/remote/http/default.rb:104:in `request'
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/remote/bridge.rb:164:in `execute'
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/remote/w3c/bridge.rb:535:in `execute'
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/remote/w3c/bridge.rb:365:in `send_keys_to_element'
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/common/element.rb:154:in `send_keys'
    from C:/Checkin/checkin.rb:10:in `<main>'

有谁可以指出我做错了什么?

1 个答案:

答案 0 :(得分:0)

我的代码工作的第一个先决条件是,安装FireFox ESR,但在安装之前,卸载现有的firefox并删除配置文件然后使用此代码,我已经包含了select_list代码以供您参考,如果你是不需要该代码,请删除它。

fprintf(intermediateFile,"%s\n\n",operand);//step 4) write operand to file