2016-04-05 122 views
0

剛開始使用ruby + webdriver,我做了一個小腳本,我想知道爲什麼腳本不會點擊web元素然後輸入值?Ruby Selenium Webdriver - 不會點擊?

require 'rubygems' 
require 'selenium-webdriver' 

class Standard_webdriver_ruby 
    driver = Selenium::WebDriver.for :firefox 
    driver.get 'http://demoqa.com/contact/' 
    driver.manage.window.maximize 
    wait = Selenium::WebDriver::Wait.new(:timeout => 5) 

    fillFormData = Array.new('rob', '[email protected]', 'whoop', 'Message content') 

    name_field = driver.find_element :css => ('#wpcf7-f375-p28-o1 > form > p:nth-child(2) > span > input') 
    name_field.click 
    name_field.send_keys(fillFormData[0]) 
    email_field = driver.find_element :css => '#wpcf7-f375-p28-o1 > form > p:nth-child(3) > span > input' 
    email_field.click 
    email_field.send_keys(fillFormData[1]) 
    subject_field = driver.find_element :css => '#wpcf7-f375-p28-o1 > form > p:nth-child(4) > span > input' 
    subject_field.click 
    subject_field.send_keys(fillFormData[2]) 
    message_field = driver.find_element :css => '#wpcf7-f375-p28-o1 > form > p:nth-child(5) > span > textarea' 
    message_field.click 
    message_field.send_keys(fillFormData[3]) 
end 
+0

什麼是你得到的錯誤? –

+0

in'initialize':錯誤的參數數量(4爲0..2)(ArgumentError)我需要將它添加到def初始化塊嗎? @VigneshParamasivam – Speedychuck

+0

初始化數組不正確。閱讀紅寶石http://ruby-doc.org/core-2.2.0/Array.html –

回答