我在不同浏览器中运行脚本时出现问题:我的脚本在Chrome,Firefox中运行良好,但IE和PhantomJS存在问题。最奇怪的是,几天前我在PhantomJS中成功完成了相同的脚本,我确信没有人改变宝石/浏览器。 这是我想要执行的脚本:
class HomePage
....
link(:signInLink, :text=>"Sign In")
....
def log_in(username="admin", password="admin123")
self.signInLink_element.when_present(60).click//hangs here
self.login_element.when_present(60)
self.username = username
self.password = password
self.signIn_element.click
end
页面的HTML代码:
<div class="user-display">
<span class="user-actions">
<a rel="nofollow" href="/RedisCache/Users/Account/LogOn?ReturnUrl=%2FRedisCache%2F">
Sign In
</a>
</span>
</div>
通过黄瓜运行我的脚本我接下来的例外(PhantomJS):
timed out after 60 seconds, waiting for {:text=>"Sign In", :tag_name=>"a"} to become present(Watir::Wait::TimeoutError)
当我试图重现这种情景时,手动&#34;使用irb我在尝试点击登录链接(PhantomJS)时遇到了下一个例外:
Selenium::WebDriver::Error::ElementNotVisibleError: Error Message => 'Element is not currently visible and may not be manipulated'
caused by Request => {"headers":{"Accept":"application/json","Connection":"close","Content-Length":"2","Content-Type":"application/x-www-form-urlencoded","Host":"127.0.0.1:8910","User-Agent":"Ruby"},"httpVersion":"1.1","method":"POST","post":"{}","postRaw":"{}","url":"/click","urlParsed":{"anchor":"","query":"","file":"click","directory":"/","path":"/click","relative":"/click","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/click","queryKey":{},"chunks":["click"]},"urlOriginal":"/session/ed325840-496d-11e4-9570-2d0549eccb44/element/%3Awdc%3A1412169736003/click"} (ReqHand)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/http/common.rb:59:in `new'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/http/common.rb:59:in `create_response'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/http/default.rb:66:in `request'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/bridge.rb:638:in `raw_execute'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/bridge.rb:616:in `execute'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/bridge.rb:373:in `clickElement'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/common/element.rb:54:in `click'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.11/lib/watir-webdriver/elements/element.rb:132:in `click'
当我在IE浏览器中运行脚本时,无论我是在运行黄瓜还是尝试点击此链接&#34;手动&#34;,我都会挂起。我可以看到链接只是闪烁,就像丢失/获得焦点一样。 我试图降级PhantomJS版本并重新安装它,但没有任何帮助。 有什么建议? IE版本是9.0.8112 PhantomJS版本是1.9.7.0 所有宝石都有最新版本。
答案 0 :(得分:1)
我过去曾遇到过:文本选择器和IE驱动程序的问题。我对我来说非常挑剔,有时会过去,有时会失败。我切换到其中一个:
link(:SignInLink, href: "/RedisCache/Users/Account/LogOn?ReturnUrl=%2FRedisCache%2F")
link(:SignInLink, xpath: "//span[@class='user-actions']/a[contains(@href,'Users/Account/LogOn')]")