gpt4 book ai didi

watir - Selenium::WebDriver::Error::MoveTargetOutOfBoundsError:元素无法滚动到 View 中:[object HTMLSpanElement]

转载 作者:行者123 更新时间:2023-12-01 11:53:32 25 4
gpt4 key购买 nike

此页面上发生了一些奇怪的事情:

require "watir-webdriver"
b = Watir::Browser.new
b.goto "http://mideastunes.com/"
b.div(class: "feat-container").element(css: "a span").present?
=> true
b.div(class: "feat-container").element(css: "a span").click

Selenium::WebDriver::Error::MoveTargetOutOfBoundsError: Element cannot be scrolled into view:[object HTMLSpanElement]
from /Users/zeljko/.rvm/gems/ruby-1.9.2-p290@gretel/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok'
from /Users/zeljko/.rvm/gems/ruby-1.9.2-p290@gretel/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
from /Users/zeljko/.rvm/gems/ruby-1.9.2-p290@gretel/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/remote/http/common.rb:59:in `new'
from /Users/zeljko/.rvm/gems/ruby-1.9.2-p290@gretel/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/remote/http/common.rb:59:in `create_response'
from /Users/zeljko/.rvm/gems/ruby-1.9.2-p290@gretel/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/remote/http/default.rb:64:in `request'
from /Users/zeljko/.rvm/gems/ruby-1.9.2-p290@gretel/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
from /Users/zeljko/.rvm/gems/ruby-1.9.2-p290@gretel/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/remote/bridge.rb:590:in `raw_execute'
from /Users/zeljko/.rvm/gems/ruby-1.9.2-p290@gretel/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/remote/bridge.rb:568:in `execute'
from /Users/zeljko/.rvm/gems/ruby-1.9.2-p290@gretel/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/remote/bridge.rb:350:in `clickElement'
from /Users/zeljko/.rvm/gems/ruby-1.9.2-p290@gretel/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/common/element.rb:34:in `click'
from /Users/zeljko/.rvm/gems/ruby-1.9.2-p290@gretel/gems/watir-webdriver-0.5.3/lib/watir-webdriver/elements/element.rb:107:in `click'
from (irb):48
from /Users/zeljko/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'

我正在尝试单击此跨度:
<span class="feature-prev-icon icon"></span>

我可以用这个点击它:
b.span(class: "feature-prev-icon icon").click

但我想用这个点击它:
b.div(class: "feat-container").element(css: "a span").click

环境:Mac OS X 10.7.3、Firefox 10.0.1、ruby 1.9.2p290、selenium-webdriver 2.19.0、watir-webdriver 0.5.3

最佳答案

编辑:这不是错误。

正如其他回答者所指出的那样,您正在与之交互的元素在屏幕外,除了复杂的交互之外,无法滚动到屏幕上。

这可能会做你想要的:

b.div(class: "feat-container").elements(css: "a span")[2].click

在这种情况下,您可能想要做的不是检查:

b.div(class: "feat-container").element(css: "a span").present?

循环遍历每个 child ,检查其边界框是否在屏幕上,特别是在这种情况下,左坐标是非负的。

这对于 WebDriver 来说有点不直观——不幸的是,并没有真正好的方法来处理潜在的问题。

关于watir - Selenium::WebDriver::Error::MoveTargetOutOfBoundsError:元素无法滚动到 View 中:[object HTMLSpanElement],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9270259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com