我正在尝试使用所附屏幕的关键字“选择文件”来浏览多个文件(一个接一个)。
下面是我的步骤:
Scroll Element Into View xpath=//span[contains(@class,'filebrowse .click')]
Wait Until Element is visible xpath=//span[contains(@class,'filebrowse .click')]
Set Focus To Element xpath=//span[contains(@class,'filebrowse .click')]
Choose File xpath=//span[contains(@class,'filebrowse .click')] ${file_path}
在上面的步骤中,我收到以下错误-“选择文件”:
WebDriverException: Message: unknown error: cannot focus element
(Session info: chrome=71.0.3578.98)
(Driver info: chromedriver=2.45.615291
(ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.10586 x86_64)
答案 0 :(得分:0)
我使用下面的代码并正常工作。
使用的库:
Library pyautogui
Library ImageHorizonLibrary
代码示例:
Scroll Element Into View xpath=//div[1]/div[5]/a/span
Wait Until Element is visible xpath=//div[1]/div[5]/a/span
Set Focus To Element xpath=//div[1]/div[5]/a/span
Click Element xpath=//div[1]/div[5]/a/span
Sleep 5s
pyautogui.Typewrite file_name.jpg
pyautogui.Key Down 'enter'
ImageHorizonLibrary.Press Combination Key.enter
Sleep 15s
为此,我必须将文件“ file_name.jpg”保留在默认浏览文件夹中。 通过示例代码运行确定了默认文件夹。