rubycdp / ferrum

Headless Chrome Ruby API
https://ferrum.rubycdp.com
MIT License
1.71k stars 123 forks source link

Node#select picks option with empty value instead provided value #229

Closed Mifrill closed 2 years ago

Mifrill commented 2 years ago

https://github.com/rubycdp/ferrum/issues/58#issuecomment-989725877

<select class="select required hasHelp"
        tabindex="3" name="applicant[passport_country_code]"
        id="applicant_passport_country_code"
        autocomplete="off">
  <option value=""></option>
  <option value="AF">Afghanistan</option>
  <option value="AU">Australia</option>
  <option value="AT">Austria</option>
  <option value="AZ">Azerbaijan</option>
</select>

Actual:

browser.at_xpath("//select[@id='applicant_passport_country_code']").select("AU").selected # => [""]

Expected:

browser.at_xpath("//select[@id='applicant_passport_country_code']").select("AU").selected # => ["Australia"]
zsan commented 2 years ago

Hello @Mifrill

I just found a possible bug that related to this select method. This (possible) bug is raised when i try to select inside iframe

frame = browser.frames[1]
frame.at_xpath("//select[@name='brandSelected']").click.select("VISA", by: :text)

# Ferrum::BrowserError Exception: Argument should belong to the same JavaScript world as target object
Mifrill commented 2 years ago

Hi, @zsan yeah, it looks so, it should be with a DOM.resolveNode usage, good catch, thank you!