php - Selenium:如何从选择菜单中选择一个选项?

标签 php selenium phpunit selenium-rc

我正在使用 PHPUnit Selenium 扩展在 PHP 中编写 Selenium 测试。

我知道如何在文本字段中输入内容:

$this->type('fieldName', 'value');

但是如何从下拉菜单中选择一个选项呢?

最佳答案

要扩展其他(准确的)答案,您可以根据选项的标签、值、ID 或索引进行选择。来自 http://release.seleniumhq.org/selenium-core/1.0/reference.html 上的官方引用资料:

select(selectLocator, optionLocator)

Arguments:

  • selectLocator - an element locator identifying a drop-down menu
  • optionLocator - an option locator (a label by default)

Select an option from a drop-down using an option locator.

Option locators provide different ways of specifying options of an HTML Select element (e.g. for selecting a specific option, or for asserting that the selected option satisfies a specification). There are several forms of Select Option Locator.

  • label=labelPattern: matches options based on their labels, i.e. the visible text. (This is the default.)
    • label=regexp:^[Oo]ther
  • value=valuePattern: matches options based on their values.
    • value=other
  • id=id: matches options based on their ids.
    • id=option1
  • index=index: matches an option based on its index (offset from zero).
    • index=2

If no option locator prefix is provided, the default behaviour is to match on label.

关于php - Selenium:如何从选择菜单中选择一个选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2820112/

相关文章:

php - 如何在 Opencart 中添加子选项?

php - 尝试从数据库 jquery 检索用户名

Selenium:指向默认的 Chrome session

java - 使用 WebDriver 自动化非英语网站

php - 如果测试访问器是浪费时间,那么测试构造函数逻辑呢?

php - 收到警告 "Header may not contain more than a single header, new line detected"

javascript - Selenium 。 HtmlUnitDriver。如何启用 JavaScript 和 Cookie?

在 PhpStorm 上安装 PHPUnit

php - 如何跨多个测试在 PHPUnit 中模拟测试 Web 服务?

javascript - 使用 CodeIgniter 中的复选框生成特定行的 Excel 报告