我使用Ruby熟悉Watir-Webdriver中的Page Objects,但现在我试图用Ruby定义Selenium-Webdriver中的Page Objects,并面对下面的问题。请任何人帮忙。
require "selenium-webdriver"
require "page-object"
Firstname = {id: "firstname"}
@driver = Selenium::WebDriver.for :firefox
@driver.get ("http://www.practiceselenium.com/practice-form.html")
@driver.manage().window.maximize()
@driver.find_element(Firstname).send_keys "User1"
无法找到元素:{"方法":" id","选择器":"名字"}(Selenium :: WebDriver :: Error :: NoSuchElementError)
答案 0 :(得分:0)
您指定的页面上没有id: "firstname"
属性。请尝试name: "firstname"
:
require "selenium-webdriver"
require "page-object"
Firstname = {name: "firstname"}
@driver = Selenium::WebDriver.for :firefox
@driver.get ("http://www.practiceselenium.com/practice-form.html")
@driver.manage().window.maximize()
@driver.find_element(Firstname).send_keys "User1"
或以更面向对象的方式:
require "selenium-webdriver"
require "page-object"
class PraticeForm
include PageObject
page_url "http://www.practiceselenium.com/practice-form.html"
text_field(:firstname, :name => 'firstname')
end
browser = Selenium::WebDriver.for :firefox
my_page_object = PraticeForm.new(browser)
my_page_object.goto
my_page_object.firstname = "User1"