当我运行下面的代码时,最后一行的预期工作。我没有收到错误,但代码行无法正常工作。我该如何解决这个问题?
require "watir-webdriver"
test = "test"
ia1 = "http://" + test + "mypurefleet.pureenergyservices.com/"
e = Watir::Browser.new :chrome
e.goto(ia1)
e.frame(:name => "content").text_field(:name => "txtPwd").set "name"
当我在IRB中运行代码时,我得到以下响应。
[14.628][INFO]: waiting for pending navigations...
[14.628][INFO]: done waiting for pending navigations
[14.658][INFO]: waiting for pending navigations...
[14.659][INFO]: done waiting for pending navigations
[14.659][INFO]: sending WebDriver response: 200 {
"sessionId": "65f50d0fd6ce5acad36bf310db8a7ef",
"status": 7,
"value": {
"message": "no such element\n (Session info: chrome=27.0.1453.110)\n (Dr
iver info: chromedriver=2.0,platform=Windows NT 6.1 SP1 x86)"
}
}
[14.667][INFO]: received WebDriver request: POST /session/65f50d0fd6ce5acad36bf3
10db8a7ef/element {
"using": "xpath",
"value": ".//frame[@name='content']"
}
[14.669][INFO]: waiting for pending navigations...
[14.670][INFO]: done waiting for pending navigations
[14.688][INFO]: waiting for pending navigations...
[14.688][INFO]: done waiting for pending navigations
[14.689][INFO]: sending WebDriver response: 200 {
sessionId: 65f50d0fd6ce5acad36bf310db8a7ef,
status: 0,
value: {
ELEMENT: 0.1280214337166388:1
}
}
.
.
.
.
.
[15.000][INFO]: waiting for pending navigations...
[15.001][INFO]: done waiting for pending navigations
[15.025][INFO]: waiting for pending navigations...
[15.025][INFO]: done waiting for pending navigations
[15.026][INFO]: sending WebDriver response: 200 {
"sessionId": "65f50d0fd6ce5acad36bf310db8a7ef",
"status": 0,
"value": null
}
[15.032][INFO]: received WebDriver request: POST /session/65f50d0fd6ce5acad36bf3
10db8a7ef/element/0.24873712522143:1/value {
"value": [ "name" ]
}
[15.033][INFO]: waiting for pending navigations...
[15.034][INFO]: done waiting or pending navigations
[15.092][INFO]: waitingforpendingnavigations...
[15.093][INFO]: done waiting for pending navigations
[15.093][INFO]: sending WebDriver response: 200 {
"sessionId": "65f50d0fd6ce5acad36bf310db8a7ef",
"status": 0,
"value": null
}
=> nil
irb(main):007:0>
答案 0 :(得分:3)
在Mac上正常工作:
MEDBEDbs-iMac:~ medbedb$ irb
1.9.3p392 :001 > require "watir-webdriver"
=> true
1.9.3p392 :002 > test = "test"
=> "test"
1.9.3p392 :003 > ia1 = "http://" + test + "mypurefleet.pureenergyservices.com/"
=> "http://testmypurefleet.pureenergyservices.com/"
1.9.3p392 :004 > e = Watir::Browser.new :chrome
=> #<Watir::Browser:0x..fbf7bb9bed066d83c url="about:blank" title="about:blank">
1.9.3p392 :005 > e.goto(ia1)
=> "http://testmypurefleet.pureenergyservices.com/"
1.9.3p392 :006 > e.frame(:name => "content").text_field(:name => "txtPwd").set "name"
=> {}
1.9.3p392 :007 > e.frame(:name => "content").text_fields.each { |p| puts p.html }
<input type="text" name="txtUser" size="20" maxlength="60" title="User ID">
<input type="password" name="txtPwd" size="20" maxlength="40" title="Password">
=> [#<Watir::TextField:0x..f95bb2b33ebcdbb2e located=true selector={:element=>(webdriver element)}>, #<Watir::TextField:0x130f931c73c6f6f8 located=true selector={:element=>(webdriver element)}>]
尝试更新chromedriver,同时尝试:
gem update --system
gem update