【问题标题】:How to get the text of the selected option using Selenium 2 PHPUnit如何使用 Selenium 2 PHPUnit 获取所选选项的文本
【发布时间】:2015-10-11 17:25:05
【问题描述】:

我试图在我的 Selenium 程序中获取文本“高光纸贴纸”,但我的程序所能做的就是获取所有选项的文本。任何可能帮助我完成此任务的建议或语法将不胜感激。

<select id="attr1" class="op_select" name="attr1">
  
  <option value="16506">Matte Paper Sticker</option>
  <option selected="selected" value="13187">High Gloss Paper Sticker</option>
  <option value="16507">High Gloss Vinyl Sticker</option>

</select>

【问题讨论】:

    标签: html selenium selenium-webdriver phpunit


    【解决方案1】:

    学习Xpath,你会没事的。

    public IWebElement Attr1 {
         get { 
            return this.browser.FindElement(By.XPath(@"//select[@id='attr1']/option[@selected='selected']")
        }
    }
    

    【讨论】:

      【解决方案2】:

      id 是查找元素的最快方式。

      这只是一个例子 $id_select_box = $this->webDriver->findElement(\WebDriverBy::id('select_box')); $selected_option = new \WebDriverSelect($id_select_box); $this->assertEquals("String", $selected_option->getFirstSelectedOption()->getText());

      【讨论】:

        猜你喜欢
        • 2015-10-23
        • 1970-01-01
        • 2016-06-15
        • 2020-03-11
        • 2016-12-25
        • 2013-07-17
        • 2011-09-21
        • 1970-01-01
        • 2011-09-19
        相关资源
        最近更新 更多