【问题标题】:"Choose File" in "seleniumlibrary" in robotframework机器人框架中“seleniumlibrary”中的“选择文件”
【发布时间】:2019-06-22 21:04:06
【问题描述】:

我正在尝试使用关键字“选择文件”浏览多个文件(一个接一个)。

  • 红色圈出的是用于浏览文件的 Web 元素(右上角)。
  • 页面代码以红色突出显示。
  • xpath 用黑色圈出(左下角),搜索时会依次突出显示浏览文件的两个 Web 元素。

以下是我的步骤:

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)

【问题讨论】:

  • 添加红圈元素的html代码片段
  • 这里是代码 sn-p :

标签: selenium selenium-webdriver selenium-chromedriver robotframework


【解决方案1】:

我使用了下面的代码并且工作正常。

使用的库:

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”保存在默认浏览文件夹中。 通过示例代码运行确定了默认文件夹。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-18
    • 2017-09-16
    • 2012-04-24
    • 2019-03-16
    • 1970-01-01
    • 2014-09-15
    • 1970-01-01
    • 2020-03-17
    相关资源
    最近更新 更多