当在 Safari 浏览器 11.0.1 的自动完成文本字段(Kendo UI)上使用 sendKeys / clear 时,在 Selenium-Ruby 中编写自动化测试时,
测试代码:
actions.push(is_element_enabled?(PROF_IN_CHARGE,'PROF_IN_CHARGE'))
actions.push(is_element_displayed?(PROF_IN_CHARGE,'PROF_IN_CHARGE'))
actions.push(type(PROF_IN_CHARGE,first_name, 'PROF_IN_CHARGE'))
硒方法:
def is_element_enabled?(locator, name, raise_exception = true)
$logger.info "Verify whether #{name} is enabled."
highlight(web_driver.find_element(locator))
web_driver.find_element(locator).enabled?
$logger.info "Element enabled: #{name}"
def is_element_displayed?(locator, name, raise_exception = true, log_error = true)
$logger.info(__method__) { "Verifying element #{name}" }
$logger.debug(__method__) { locator }
web_driver.find_element(locator).displayed?
highlight(web_driver.find_element(locator), 0, "red")
return true
def type(locator, text, name, raise_exception = true)
$logger.info(__method__) { "Typing #{text} to #{name}" }
$logger.debug(__method__) { locator }
highlight(web_driver.find_element(locator), 0, "red")
#Clear existing text before typing
web_driver.find_element(locator).clear
web_driver.find_element(locator).send_keys(text)
显示以下错误:
# --- Caused by: ---
# Selenium::WebDriver::Error::ElementNotVisibleError:
# An element command could not be completed because the element is not visible on the page.
# /Users/admin/.rvm/gems/ruby-2.4.1/gems/selenium-webdriver-3.6.0/lib/selenium/webdriver/remote/response.rb:71:in `assert_ok'
这是日志:
I, [2017-12-11T15:19:00.611929 #5324] INFO -- : Verify whether PROF_IN_CHARGE is enabled.
I, [2017-12-11T15:19:00.635876 #5324] INFO -- : Element enabled: PROF_IN_CHARGE
I, [2017-12-11T15:19:00.635940 #5324] INFO -- is_element_displayed?: Verifying element PROF_IN_CHARGE
D, [2017-12-11T15:19:00.635964 #5324] DEBUG -- is_element_displayed?: {:id=>"fcCreateMainAssingee"}
I, [2017-12-11T15:19:00.647651 #5324] INFO -- is_element_displayed?: true
I, [2017-12-11T15:19:00.660760 #5324] INFO -- type: Typing Report to PROF_IN_CHARGE
D, [2017-12-11T15:19:00.660834 #5324] DEBUG -- type: {:id=>"fcCreateMainAssingee"}
E, [2017-12-11T15:19:00.685450 #5324] ERROR -- create_new_matter: failed.
I, [2017-12-11T15:19:00.725482 #5324] INFO -- screenshot: Screenshot saved in path: /Users/admin/PivotQA/screenshots/2017-12-11_1
5_18_15/MattersLib_create_new_matter_20171211_151900.png
E, [2017-12-11T15:19:00.725531 #5324] ERROR -- : An element command could not be completed because the element is not visible on t
he page.
即使使用 selenium 的启用成功检查该元素是否已启用且可见,也会发生这种情况?并显示?方法。
但是,在 chrome、IE 和 Edge 等其他浏览器上看不到这个问题。
我已经使用 javascript("document.getElementById('fcCreateMainAssingee'.value='text')") 来更改该文本字段的值并且效果很好,但是没有显示动态选项下拉列表,这就是问题所在。
那么,有没有人遇到过类似的问题并解决了呢?能得到你的帮助会很棒。
另外,如果有任何其他方法可以完成此操作,请提出建议。
这是该自动完成字段的 DOM:
<input formcontrolname="fcCreateMainAssingee" id="fcCreateMainAssingee" type="text" class="ng-untouched ng-pristine ng-valid k-input" data-role="autocomplete" placeholder="Username" autocomplete="off" role="textbox" aria-haspopup="true" aria-disabled="false" aria-readonly="false" aria-owns="fcCreateMainAssingee_listbox" aria-autocomplete="list" style="width: 100%;">
谢谢!