【问题标题】:How to set element attribute using phpunit-selenium如何使用 phpunit-selenium 设置元素属性
【发布时间】:2015-02-21 18:17:36
【问题描述】:

我想做这样的事情:

// pseudocode
$this->byCssSelector('p')->setAttribute('attributename', 'attributevalue');

如何在phpunit-selenium 中做到这一点?

【问题讨论】:

    标签: php selenium selenium-webdriver phpunit


    【解决方案1】:

    你需要使用execute()执行javascript并使用setAttribute()设置属性:

    $this->execute(array(
        'script' => "document.getElementById('my_id').setAttribute('name', 'value');", 
        'args' => array()
    ));
    

    【讨论】:

    • 注意,->value() 方法仍然适用于设置 value 属性。在 selenium 2.43 中删除了获取,但他们将底层 POST 留在了有线协议中。
    猜你喜欢
    • 1970-01-01
    • 2017-10-21
    • 2013-11-24
    • 2015-03-02
    • 2023-03-05
    • 2017-04-28
    • 2014-05-11
    • 2017-01-18
    • 2019-04-21
    相关资源
    最近更新 更多