在Appium中,我尝试使用XPath访问Web视图中的元素(即点按按钮或编辑文本字段中的文本)元素。但我能够访问本机元素,而不是webview元素。
我使用Appium检查器获得了XPath。
背景是" NATIVE"因为切换到" WEBVIEW"我收到了HTML解析错误
XPATH : "//XCUIElementTypeOther[@name='Scripts: Responsive IFrames for embedding webpages']/XCUIElementTypeOther[8]/XCUIElementTypeTextView"
/Users/dxcdr/.rvm/gems/ruby-2.2.6/gems/appium_lib_core-1.5.1/lib/appium_lib_core/common/wait.rb:96:in `until_true': timed out after 60 seconds (Error Domain=com.facebook.WebDriverAgent Code=1 "The element '"Click to select all (also copies in IE)" Button' is not visible on the screen and thus is not interactable" UserInfo={NSLocalizedDescription=The element '"Click to select all (also copies in IE)" Button' is not visible on the screen and thus is not interactable}) (Appium::Core::Wait::TimeoutError)
from /Users/dxcdr/.rvm/gems/ruby-2.2.6/gems/appium_lib_core-1.5.1/lib/appium_lib_core/common/wait.rb:127:in `wait_true'
from /Users/dxcdr/.rvm/gems/ruby-2.2.6/gems/appium_lib-9.12.0/lib/appium_lib/common/wait.rb:26:in `wait_true'
from /Users/dxcdr/RubymineProjects/Test/test.rb:53:in `wait_for_xpath_visible'
from /Users/dxcdr/RubymineProjects/Test/test.rb:88:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
答案 0 :(得分:0)
您的定位器是本机上下文,而不是Web视图中的html元素,例如XCUIElementTypeOther
与网页视图元素无关
您必须切换到网络视图才能在其中进行搜索:
web_view_context = available_contexts.find {| c | c.start_with? 'WEBVIEW'}
set_context web_view_context