我正在尝试交互来自WATIR代码的阴影DOM。我使用了JustinKo的解决方案,如下所示。但是它抛出了以下错误
Backtrace:: javascript error: Cannot read property 'toLowerCase' of undefined (Selenium::WebDriver::Error::JavascriptError)当程序遇到这一行时
Watir.element_class_for(element.tag_name.downcase).new(scope, element: element)我的程序
require 'watir'
# Monkey-patch due to being unable to check the tag name of the shadow root
class Watir::Browser
def wrap_element(scope, element)
Watir.element_class_for(element.tag_name.downcase).new(scope, element: element)
rescue Selenium::WebDriver::Error::UnknownError # need a better rescue
Watir::Element.new(scope, element: element)
end
end
def expand_root_element(element, browser)
browser.execute_script("return arguments[0].shadowRoot", element)
end
b=Watir::Browser.new
b.goto 'http://alis-core-lin01:8082/core_pl_env5/alis#alis'
element=b.element(xpath: "//vaadin-text-field[@id='user.name']")
shadow_dom=expand_root_element(element,b)
shadow_dom.text_field.set 'Raj'
puts 'Raj'HTML

发布于 2020-12-31 01:24:59
在这一点上,这里没有真正好的答案。最初的问题是附加到元素的阴影dom实际上没有标记名。因此,贾斯汀的猴子补丁。但随着更新,该补丁不再有效。新的问题是,影子shadowRoot被附加到实数元素上,但dom本身并不是实数元素。它就像一个准元素。
Selenium::WebDriver::Error::JavascriptError,所以你的救援线需要更新以纠正错误。javascript error: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'这是在wire协议上的一个内部API调用的结果。例如,我跟踪错误到selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/http/default.rb:81 API调用返回一个有效负载为"{"value":{"error":"javascript error","message":"javascript error: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.\n (Session info: chrome=87.0.4280.88)"的内部500错误,我不知道如何解决这个问题。https://stackoverflow.com/questions/64768912
复制相似问题