在使用 Metamask 登錄后,我正在嘗試在
查完網址后,程式點擊相應按鈕上傳檔案

然后等待 2 秒,然后將影像路徑粘貼到Name文本框中,然后按Enter

所以檔案最終被正確上傳到這個頁面。
問題是,上面的程式之所以有效,是因為在執行之前滿足以下條件:
- The current window open is the Chrome Browser tab (instead of the Python program itself, i.e. Spyder environment in my case)
- After clicking the button to upload a file, the
Nametextbox is selected by default, regardless the current path it opens with.
So, I'm kind of perfectionist, and I would like to know if there's a method (using Selenium or other Python module) to check if there's an Open File dialog open before doing the rest of the work.
I tried print(driver.window_handles) right after clicking that button, but Selenium did not recognize the Open File dialog as another Chrome Window, it just printed the tab ID of this page, so it seems to me that Selenium can't do what I want, but I'm not sure, so I would like to hear what other methods could be used in this case.
PS:我必須以這種方式執行此程序,因為該send_keys()方法在此頁面中不起作用
uj5u.com熱心網友回復:
您嘗試與之互動的對話框是本機作業系統對話框,它不是一種瀏覽器處理程式/對話框/選項卡等。因此 Selenium 無法指示它并且無法處理它。有幾種方法可以處理此類 OS 本機對話框。我不想復制 - 粘貼現有的解決方案。例如,您可以嘗試此解決方案。它非常詳細,看起來不錯。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/421988.html
標籤:
下一篇:XPath,嵌套條件
