我想從this website中選擇隱藏的選擇列表,然後選擇選項0 - 0,5
。我不斷收到(Selenium::WebDriver::Error::ElementNotVisibleError)
。如何從隱藏的選擇列表中選擇一個值?
完整的錯誤日誌:
/Users/#/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/response.rb:51:in `assert_ok': {"errorMessage":"Element is not currently visible and may not be manipulated","request":{"headers":{"Accept":"application/json","Accept-Encoding":"gzip;q=1.0,deflate;q=0.6,identity;q=0.3","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/115feff0-0b40-11e4-a69f-e39c52da2b2d/element/%3Awdc%3A1405333055513/click"}} (ReqHand) (Selenium::WebDriver::Error::ElementNotVisibleError)
from /Users/#/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
from /Users/#/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/http/common.rb:59:in `new'
from /Users/#/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/http/common.rb:59:in `create_response'
from /Users/#/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/http/default.rb:66:in `request'
from /Users/#/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
from /Users/#/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/bridge.rb:634:in `raw_execute'
from /Users/#/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/bridge.rb:612:in `execute'
from /Users/#/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/bridge.rb:369:in `clickElement'
from /Users/#/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/common/element.rb:54:in `click'
from /Users/#/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/watir-webdriver-0.6.10/lib/watir-webdriver/elements/select.rb:155:in `select_by_string'
from /Users/#/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/watir-webdriver-0.6.10/lib/watir-webdriver/elements/select.rb:131:in `select_by'
from /Users/#/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/watir-webdriver-0.6.10/lib/watir-webdriver/elements/select.rb:64:in `select'
from aegon.rb:15:in `<main>'
這是選擇列表中的HTML是什麼樣子:
<select name="werkervaring" class="selectBox" style="display: none;">
<option value="">Geen voorkeur</option>
<option value="1">0 - 0,5</option>
<option value="2">0,5 - 1</option>
<option value="3">1 - 2</option>
<option value="4">2 - 5</option>
<option value="5">5 - 10</option>
<option value="6">> 10</option>
</select>
注意style="display: none;"
是我不斷收到錯誤的原因。
下面是我使用的代碼:
require 'watir'
b = Watir::Browser.new :phantomjs
b.goto('https://werkenbijaegon.nl/vacatures/?utm_source=aegon.nl&utm_medium=link&utm_content=home&utm_campaign=werkenbij')
b.select_list(:name => 'werkervaring').select '0 - 0,5'
b.close
的問題是我怎麼能選擇一個隱藏的選擇列表中選擇0 - 0,5
?我應該用別的東西代替Watir嗎?
簡答:如果用戶不行,Selenium不能。 – xyz
用戶可以。隱藏的選擇列表以某種方式連接到可見和樣式的列表。看看這個html。如果我通過可見的方式選擇「0 - 0,5」,隱藏的方法也會改變,並完成所有工作。 – narzero
[Watir-webdriver - 選擇一個列表顯示風格:無]的可能的重複(http://stackoverflow.com/questions/24391437/watir-webdriver-select-a-list-display-style-none) –