我想为这个网站编写一些测试:https://roomy-fire-houseboat.glitch.me/但无法找到任何元素。我可以启动网站,然后添加 5 秒的睡眠时间。
这是 RubyMine 中的错误:
Selenium::WebDriver::Error::NoSuchElementError: no such element: Unable to locate element: {"method":"css selector","selector":"#number"}
(Session info: chrome=123.0.6312.59); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
GetHandleVerifier [0x00534CE3+225091]
(No symbol) [0x00464E31]
(No symbol) [0x00309A7A]
(No symbol) [0x0034175B]
(No symbol) [0x0034188B]
(No symbol) [0x00377882]
(No symbol) [0x0035F5A4]
(No symbol) [0x00375CB0]
(No symbol) [0x0035F2F6]
(No symbol) [0x003379B9]
(No symbol) [0x0033879D]
sqlite3_dbdata_init [0x009A9A83+4064547]
sqlite3_dbdata_init [0x009B108A+4094762]
sqlite3_dbdata_init [0x009AB988+4072488]
sqlite3_dbdata_init [0x006AC9E9+930953]
(No symbol) [0x00470804]
(No symbol) [0x0046AD28]
(No symbol) [0x0046AE51]
(No symbol) [0x0045CAC0]
BaseThreadInitThunk [0x76EB7BA9+25]
RtlInitializeExceptionChain [0x779EBDAB+107]
RtlClearBits [0x779EBD2F+191]
C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/response.rb:55:in `assert_ok'
C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/response.rb:34:in `initialize'
C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/http/common.rb:83:in `new'
C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/http/common.rb:83:in `create_response'
C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/http/default.rb:104:in `request'
C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/bridge.rb:620:in `execute'
C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/bridge.rb:537:in `find_element_by'
C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/common/search_context.rb:63:in `find_element'
这是当前行,我用来在网站上查找文本框。
driver.find_element(:id, 'number')
我也尝试过:css和:xpath。
当我检查元素时,我得到以下信息:
id =“号码” 类型=“文本”
选择器=#number
xpath = //*[@id="number"]
不确定你的程序是什么,我编写了以下程序,它对我来说效果很好。
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome
driver.navigate.to 'https://roomy-fire-houseboat.glitch.me/'
driver.find_element(id: 'number').send_keys '2'
driver.find_element(id: 'start').click
sleep 10
您可以尝试一下吗,如果您遇到任何问题请告诉我。