wangkun 1 year ago
parent
commit
e04bc4ff3c
1 changed files with 13 additions and 12 deletions
  1. 13 12
      shipinhao/shipinhao_search/shipinhao_search.py

+ 13 - 12
shipinhao/shipinhao_search/shipinhao_search.py

@@ -187,8 +187,8 @@ class ShipinhaoSearch:
             # 其中 Appium、UiAutomator2、Selendroid、Espresso 用于 Android,XCUITest 用于 iOS
             "showChromedriverLog": True,
             # "chromeOptions": {"androidProcess": "com.tencent.mm:appbrand0"},
-            "chromeOptions": {"androidProcess": "com.tencent.mm:tools"},
-            # "chromeOptions": {"androidProcess": "com.tencent.mm"},
+            # "chromeOptions": {"androidProcess": "com.tencent.mm:tools"},
+            "chromeOptions": {"androidProcess": "com.tencent.mm"},
             'enableWebviewDetailsCollection': True,
             'setWebContentsDebuggingEnabled': True,
             'chromedriverExecutable': chromedriverExecutable,
@@ -243,16 +243,17 @@ class ShipinhaoSearch:
     def check_to_webview(cls, log_type, crawler, driver: WebDriver):
         webviews = driver.contexts
         Common.logger(log_type, crawler).info(f"webviews:{webviews}")
-        driver.switch_to.context(webviews[1])
-        time.sleep(1)
-        windowHandles = driver.window_handles
-        for handle in windowHandles:
-            driver.switch_to.window(handle)
-            if driver.find_element(By.XPATH, '//div[@class="unit"]'):
-                Common.logger(log_type, crawler).info('切换 webview 成功')
-                return "成功"
-            else:
-                Common.logger(log_type, crawler).info("切换 webview 失败")
+        for webview in webviews:
+            driver.switch_to.context(webview)
+            time.sleep(1)
+            windowHandles = driver.window_handles
+            for handle in windowHandles:
+                driver.switch_to.window(handle)
+                if driver.find_element(By.XPATH, '//div[@class="unit"]'):
+                    Common.logger(log_type, crawler).info('切换 webview 成功')
+                    return "成功"
+                else:
+                    Common.logger(log_type, crawler).info("切换 webview 失败")
 
     @classmethod
     def repeat_out_video_id(cls, log_type, crawler, out_video_id, env):