我通過每個線程在stackoverflow上搜索,但找不到適合我的問題的解決方案。在7/10的情況下,我的腳本正在下降,因爲他們沒有找到一個特定的元素。因此,我正在尋找一個oppurtunity來告訴我的腳本「等到這個元素出現,然後點擊它」。等到元素存在
我的代碼如下所示:
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
有沒有人有一個想法?
您看到的錯誤是什麼?請通過'@ driver.find_element(:css,「#asMain> header> a.as-Button.is-active.as-Button-inverted」)更新完全綁定的內容。 https://開頭secure.shore.com'。謝謝 – DebanjanB
適當的縮進是一個巨大的調試幫助 –
Hi @DebanjanB。我的腳本無法及時發現這個元素,因爲前端寫得不好。因此,我想強制腳本先查找元素,然後繼續。 –