我需要在混合應用程序中自動化 Web 視圖。本機部分自動化進展順利。單擊本機視圖中的按鈕之一后,應用程序將進一步導航到 Chrome 瀏覽器并打開 Web 視圖?,F在,問題是我無法使用 driver.getContextHandles() 在字符串集中獲取“WEBVIEW”。即使導航到網絡視圖后,我也只能獲得“NATIVEAPP”的值。請讓我知道我哪里出錯了,或者還有其他方法可以解決這個問題。嘗試使用 driver.getContextHandles() 獲取所有上下文,然后運行“for 循環”將驅動程序設置為 WEBVIEW 上下文,以在 webview 上執行進一步的操作。 //Below code is after clicking on the button on native view which //navigate to the web view in the chrome browser Set<String> contextNames = driver.getContextHandles(); System.out.println(contextNames); for (String conName : contextNames) { System.out.println(conName); if (conName.contains("WEBVIEW")) { driver.context(conName); } } //clicking action in the webview in browser driver.findElement(By.xpath(XYZ)).click();我期望 driver.getContextHandles() 值為:NATIVEAPP,WEBVIEW。但我只得到 NATIVEAPP 作為輸出。
1 回答

寶慕林4294392
TA貢獻2021條經驗 獲得超8個贊
為了讓您能夠在應用程序內對 webview 進行任何類型的調試。需要通過將此鍵添加到應用程序的配置中來啟用 Web 視圖調試選項:setWebContentsDebuggingEnabled 并將其值設置為 true。
添加回答
舉報
0/150
提交
取消