代码:
driver.find_element_by_name("浏览").click()
time.sleep(3)
print driver.contexts
bb = driver.contexts
print bb
driver.switch_to.context(bb[1])
print driver.page_source
print driver.current_url
appium log 信息:
info: --> GET /wd/hub/session/e1e671d2-e5f4-4882-9455-35f859c95ca7/contexts {}
info: [debug] [REMOTE] Getting WebKitRemoteDebugger pageArray
info: [debug] Responding to client with success: {"status":0,"value":["NATIVE_APP","WEBVIEW_1","WEBVIEW_2","WEBVIEW_3"],"sessionId":"e1e671d2-e5f4-4882-9455-35f859c95ca7"}
info: <-- GET /wd/hub/session/e1e671d2-e5f4-4882-9455-35f859c95ca7/contexts 200 7.031 ms - 122 {"status":0,"value":["NATIVE_APP","WEBVIEW_1","WEBVIEW_2","WEBVIEW_3"],"sessionId":"e1e671d2-e5f4-4882-9455-35f859c95ca7"}
info: --> GET /wd/hub/session/e1e671d2-e5f4-4882-9455-35f859c95ca7/contexts {}
info: [debug] [REMOTE] Getting WebKitRemoteDebugger pageArray
info: [debug] Responding to client with success: {"status":0,"value":["NATIVE_APP","WEBVIEW_1","WEBVIEW_2","WEBVIEW_3"],"sessionId":"e1e671d2-e5f4-4882-9455-35f859c95ca7"}
info: <-- GET /wd/hub/session/e1e671d2-e5f4-4882-9455-35f859c95ca7/contexts 200 2.400 ms - 122 {"status":0,"value":["NATIVE_APP","WEBVIEW_1","WEBVIEW_2","WEBVIEW_3"],"sessionId":"e1e671d2-e5f4-4882-9455-35f859c95ca7"}
info: --> POST /wd/hub/session/e1e671d2-e5f4-4882-9455-35f859c95ca7/context {"sessionId":"e1e671d2-e5f4-4882-9455-35f859c95ca7","name":"WEBVIEW_1"}
info: [debug] Attempting to set context to 'WEBVIEW_1'
info: [debug] [REMOTE] Debugger web socket connected to url [ws://localhost:27753/devtools/page/1]
info: [debug] Responding to client with success: {"status":0,"value":"WEBVIEW_1","sessionId":"e1e671d2-e5f4-4882-9455-35f859c95ca7"}
info: <-- POST /wd/hub/session/e1e671d2-e5f4-4882-9455-35f859c95ca7/context 200 4.614 ms - 83 {"status":0,"value":"WEBVIEW_1","sessionId":"e1e671d2-e5f4-4882-9455-35f859c95ca7"}
info: --> GET /wd/hub/session/e1e671d2-e5f4-4882-9455-35f859c95ca7/source {}
info: [debug] [REMOTE] Sending javascript command
info: [debug] [REMOTE] Remote debugger data sent [{"method":"Runtime.evaluate","params":{"objectGroup":"console","includeCommandLineAPI":true,"doNotPauseOnExceptionsAndMuteConsole":true,"expression":"document.getElementsByTagName(\"html\")[0].outerHT...]
Debugger web socket received data : {"result":{"result":{"type":"string","value":"\u003Chtml\u003E\u003Chead\u003E\u003C/head\u003E\u003Cbody\u003E\u003C/body\u003E\u003C/html\u003E"},"wasThrown":false},"id":1}
info: [debug] Responding to client with success: {"status":0,"value":"<html><head></head><body></body></html>","sessionId":"e1e671d2-e5f4-4882-9455-35f859c95ca7"}
info: <-- GET /wd/hub/session/e1e671d2-e5f4-4882-9455-35f859c95ca7/source 200 61.938 ms - 113 {"status":0,"value":"<html><head></head><body></body></html>","sessionId":"e1e671d2-e5f4-4882-9455-35f859c95ca7"}
info: --> GET /wd/hub/session/e1e671d2-e5f4-4882-9455-35f859c95ca7/url {}
info: [debug] [REMOTE] Sending javascript command
info: [debug] [REMOTE] Remote debugger data sent [{"method":"Runtime.evaluate","params":{"objectGroup":"console","includeCommandLineAPI":true,"doNotPauseOnExceptionsAndMuteConsole":true,"expression":"window.location.href","returnByValue":true},"id":2...]
Debugger web socket received data : {"result":{"result":{"type":"string","value":"about:blank"},"wasThrown":false},"id":2}
info: [debug] Responding to client with success: {"status":0,"value":"about:blank","sessionId":"e1e671d2-e5f4-4882-9455-35f859c95ca7"}
info: <-- GET /wd/hub/session/e1e671d2-e5f4-4882-9455-35f859c95ca7/url 200 11.407 ms - 85 {"status":0,"value":"about:blank","sessionId":"e1e671d2-e5f4-4882-9455-35f859c95ca7"}