【发布时间】:2018-01-12 11:04:40
【问题描述】:
我搜索了 stackoverflow 上的每个线程,但找不到适合我的问题的解决方案。在 7/10 的情况下,我的脚本正在下降,因为它们没有找到一个特定的元素。因此,我正在寻找一个机会来告诉我的脚本“等这么久,直到这个元素出现,然后点击它”。
我的代码如下:
require "json"
require "selenium-webdriver"
require "test/unit"
class LogIn < Test::Unit::TestCase
def setup
@driver = Selenium::WebDriver.for :chrome
@base_url = "url"
@accept_next_alert = true
@driver.manage.timeouts.implicit_wait = 30
@verification_errors = []
end
def teardown
@driver.quit
assert_equal [], @verification_errors
end
def test_sms_newsletter
#login
@driver.get "https://secure.shore.com/merchant/sign_in"
@driver.find_element(:id, "merchant_account_email").clear
@driver.find_element(:id, "merchant_account_email").send_keys "key"
@driver.find_element(:id, "merchant_account_password").clear
@driver.find_element(:id, "merchant_account_password").send_keys
"password"
@driver.find_element(:name, "button").click
@driver.get "https://secure.shore.com"
verify { assert_equal "Shore - Manage your customers", @driver.title }
sleep 5
@driver.find_element(:css, "#asMain > header > a.as-Button.is-
active.as-Button--inverted").click
我要讨论的元素是最后一个:
@driver.find_element(:css, "#asMain > header > a.as-Button.is-active.as-Button--inverted").click
有人有想法吗?
【问题讨论】:
-
您看到的错误是什么?请通过网址
https://secure.shore.com上的@driver.find_element(:css, "#asMain > header > a.as-Button.is-active.as-Button--inverted").click更新您到底想做什么。谢谢 -
正确缩进对调试有很大帮助
-
嗨@DebanjanB。我的脚本很难及时找到这个元素,因为前端写得不好。因此我想强制脚本先找到元素然后继续。
-
您不仅在寻找,而且还在点击。对于接收
click()的元素,您需要正确的css或xpath。通过您的css,我在https://secure.shore.com上没有找到任何元素。谢谢