【问题标题】:Correct syntax to use with Click Button与单击按钮一起使用的正确语法
【发布时间】:2019-05-01 14:50:42
【问题描述】:

我正在编写一个机器人框架/Selenium 测试脚本来验证网站的登录过程。我无法获得正确的语法来自动按下登录按钮。这是机器人脚本:

*** Settings ***
Documentation     Project Automated Test
Library           SeleniumLibrary

*** Variables ***
${LOGIN URL}      http://localhost/project
${BROWSER}        Chrome

*** Test Cases ***
Valid Login
    Open Browser To Login Page
    Maximize Browser Window
    Welcome Page Should Be Open
    Login_User
    [Teardown]    Close Browser

*** Keywords ***
Open Browser To Login Page
    Open Browser    ${LOGIN URL}    ${BROWSER}

Welcome Page Should Be Open
    Page should contain  Project Tasks

Login_User
    Click Button  Login

这是登录按钮的代码:

<input class="btn" type="button" onclick="
                if(document.getElementById('authentication').style.display == 'none'){
                    $('#authentication').slideDown('slow');
                                    } else {
                    $('#authentication').slideUp('slow');
                }
                " href="#" value="Login">

当脚本启动时,Chrome 会打开并正确显示网页。我可以在网页上看到登录按钮。我已经尝试了 Click Button 定位器参数的各种组合(登录,值 = 登录,文本 = 登录)。每次尝试都会导致 Button with locator not found 消息。这是我第一个使用 Robot Framework/Selenium 的项目,因此我们将不胜感激。谢谢!

【问题讨论】:

    标签: selenium robotframework


    【解决方案1】:

    Third 参数是您的locator,您可以使用 id、name、xpath 或 css 选择器。因为 id 和 name 不可用,您可以使用 xpath 或 css 选择器。

     Login_User
            Click Button  xpath://input[@class='btn'][@value='Login']
    

    OR css 选择器

    Login_User
            Click Button  css:input.btn[value='Login']
    

    您可以参考以下robot framework 文档。

    【讨论】:

    • 这三个建议似乎都不适合我:单击按钮 "//input[@class='btn'][@value='Login']" Button with locator '"//input [@class='btn'][@value='Login']"' 未找到。单击按钮 xpath="//input[@class='btn'][@value='Login']" InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression "//input[@class=' btn'][@value='Login']" 因为以下错误:单击按钮 css="input.btn[value='Login']" InvalidSelectorException:消息:无效选择器:指定了无效或非法选择器跨度>
    • 我的错误是用= 而不是: 现在试试
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-05
    • 1970-01-01
    • 2010-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多