无法在文本字段中输入文本

时间:2018-10-09 17:55:14

标签: python selenium selenium-webdriver xpath robotframework

对于页面上的特定文本框,robotframework给我一个错误,该错误是在我使用run命令后该元素不可见。我基本上是想在文本字段中输入文本,但无法识别其在页面上的位置。

我使用了locators..xpath,id和class。

xpath=//*[@id="solution-input"]

我使用机器人框架编写的测试用例:

Wait Until Element Is Visible    xpath=//*[@id="solution-input"]    20  seconds
Set Focus To Element    xpath=//*[@id="solution-input"]
Input Text    xpath=//*[@id="solution-input"]    test

HTML代码段:

<input _ngcontent-c2="" class="col-md-6 ng-untouched ng-pristine ng-valid" id="solution-input" placeholder="Used for Opportunity Name &amp; Description" type="text">

1 个答案:

答案 0 :(得分:1)

所需元素是Angular元素,因此您可以使用(合并)解决方案中的一个或两个:

  • Wait Until Element Is Visible

    Wait Until Element Is Visible    xpath=//input[@class="col-md-6 ng-untouched ng-pristine ng-valid" and @id="solution-input"]    20  seconds
    Set Focus To Element    xpath=//*[@id="solution-input"]
    Input Text    xpath=//*[@id="solution-input"]    test
    
  • Wait Until Element Is Enabled

    Wait Until Element Is Enabled    xpath=//input[@class="col-md-6 ng-untouched ng-pristine ng-valid" and @id="solution-input"]    20  seconds
    Set Focus To Element    xpath=//*[@id="solution-input"]
    Input Text    xpath=//*[@id="solution-input"]    test
    
  • 您可以在Robotframework: Selenium2Lib: Wait Until (…) Keywords

    中找到有关Wait Until Element Is VisibleWait Until Element Is Enabled的详细讨论
  • 参考:Selenium2Library