php - 使用 PHP Selenium Webdriver 单击下拉菜单中的选项?

标签 php selenium webdriver selenium-webdriver

我正在使用 PHP Selenium Webdriver 包装器 Facebook .任何人都可以给我一个示例,说明如何从选择下拉菜单中单击或选择一个选项吗?

我试过这个:

$test = $driver->findElement( WebDriverBy::id('drop1').WebDriverBy::cssSelector("option[value='11']"));
$test->‌​click();

但它出错了:

Message : Object of class WebDriverBy could not be converted to string

最佳答案

应该是

$test = $driver->findElement( WebDriverBy::id('drop1') )
               ->findElement( WebDriverBy::cssSelector("option[value='11']") )
               ->click();

如果您正在处理“select”标签,请改用 WebDriverSelect

$select = new WebDriverSelect($driver->findElement(WebDriverBy::id('drop1')));
$select->selectByValue('11');

关于php - 使用 PHP Selenium Webdriver 单击下拉菜单中的选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19490225/

相关文章:

c# - 使用私钥对 PHP 进行数字签名,在 C# 中进行验证

selenium - 如何在 Selenium 中单击 <a> 标签

r - 如何单击 javascript "link"?是我的 xpath 还是我的 relenium/selenium 用法?

java - Selenium Webdriver 错误 "Element is not clickable at point"PrimeFaces SelectOneMenu

c# - EdgeDriver - 无法更改 Edge 中的窗口大小

php - 如何显示五行?

php - Laravel 中的错误爆炸

php - laravel中如何从同一数据库下的另一个表中获取值?

java - Selenium 2.48.2 +firefox 42 +浏览器没有被实例化

webdriver - 与元素交互抛出陈旧元素引用