红宝石| Selenium-WebDriver-单击“隐藏”按钮

时间:2018-07-09 09:55:05

标签: html css ruby selenium-webdriver hidden

我看到有很多类似的查询,但是我一直找不到我的特定问题。如果在其他地方,请告诉我!

我目前正在尝试为公司网站创建自动测试。我在Firefox v35上将Ruby与rspec和geckodriver一起使用。由于我使用的PC正在运行Windows Vista,因此不幸的是,我无法使用这些版本的较新版本。

我已经能够导航到网页并填充/单击大多数元素,但是页面上有4个带有html的按钮,例如下面的类和相关按钮:

<div class="hidden">
  <select aria-describedby="Driver1_IsAdditionalDriverRequired_Error Driver1_IsAdditionalDriverRequired_Help" autocomplete="off" data-val="true" data-val-number="The field IsAdditionalDriverRequired must be a number." data-val-range="Please answer Yes or No"
    data-val-range-max="1" data-val-range-min="0" data-val-required="The IsAdditionalDriverRequired field is required." id="Driver1_IsAdditionalDriverRequired" name="Driver1.IsAdditionalDriverRequired">
    <option selected="selected" value="-1"> </option>
    <option value="1">Yes</option>
    <option value="0">No</option>
  </select>
</div>

<button id="Driver1_IsAdditionalDriverRequired_1" data-value="1" data-index="0" class="btn btn-light valid" type="button" onclick="javascript: selectItem(this);" aria-describedby="Driver1_IsAdditionalDriverRequired_Error Driver1_IsAdditionalDriverRequired_Help"
  autocomplete="off" aria-invalid="false">Yes</button>

<button id="Driver1_IsAdditionalDriverRequired_0" data-value="0" data-index="0" class="btn btn-light valid" type="button" onclick="javascript: selectItem(this);" aria-describedby="Driver1_IsAdditionalDriverRequired_Error Driver1_IsAdditionalDriverRequired_Help"
  autocomplete="off" aria-invalid="false">No</button>

我一直在尝试查找并单击按钮的代码是:

require "selenium-webdriver"
require "rspec"

ADD_DRIVER_BUTTON = { id: "Driver1_IsAdditionalDriverRequired_0"}


def additional_driver_click()

   additional_driver_button = additional_driver_button.@driver.find_element(ADD_DRIVER_BUTTON)
   additional_driver_button.click

end

运行它时没有出现任何错误,但是没有单击按钮,因此我相信它们已被找到,但是由于“ div class =” hidden“”,因此未单击它们。当我亲自进入网页时,所有四个按钮在加载页面时都可见,并且无需任何先决条件即可手动单击

请让我知道我对隐藏类的怀疑是否是罪魁祸首,如果是,那么是否有解决方法!

如果我没有提供足够的细节或代码,我也提前致歉!

0 个答案:

没有答案