Selenium webdriver PHP webdriver如何在此处选择第三个选项

Selenium webdriver PHP webdriver如何在此处选择第三个选项,selenium-webdriver,facebook-php-webdriver,php-webdriver,Selenium Webdriver,Facebook Php Webdriver,Php Webdriver,我有下面的html,我想选择第三个选项,它是使用SeleniumPHP webdriver关闭的可选选项。谁能告诉我怎么做 在这个HTML中,所有ID都是动态生成的。因此,我不能使用id查找元素,例如,我不能使用此: $driver->findElement(WebDriverBy::id('ajax-item-ExchangeEmail-12345')); 我们可以使用cssSelector或xpath吗?如果是的话,怎么办 谢谢 <div id="ajax-item-12345

我有下面的html,我想选择第三个选项,它是使用SeleniumPHP webdriver关闭的可选选项。谁能告诉我怎么做

在这个HTML中,所有ID都是动态生成的。因此,我不能使用id查找元素,例如,我不能使用此:

$driver->findElement(WebDriverBy::id('ajax-item-ExchangeEmail-12345'));
我们可以使用cssSelector或xpath吗?如果是的话,怎么办

谢谢

<div id="ajax-item-12345" class="input-group" title="ExchangeEmail">
    <label class="input-group-addon" for="ajax-item-ExchangeEmail-12345">ExchangeEmail</label>
    <select id="ajax-item-ExchangeEmail-12345" class="form-control" name="category_resource[12345]">
        <option value="2">On (mandatory)</option>
        <option value="1">On (optional)</option>
        <option value="0">Off (optional)</option>
        <option value="3">Off (mandatory)</option>
    </select>
</div>
使用cssSelector和selectByVisibleText函数,我现在可以选择我想要的任何选项。谢谢

with(new WebDriverSelect($driver->findElement(WebDriverBy::cssSelector('div[title="ExchangeEmail"] select'))))
        ->selectByVisibleText('Off (optional)');
selectByVisibleText命令可用于使用标签文本从下拉字段中选择列表选项:

例如,要使用CSS选择器:

$selectDiv = WebDriverBy::cssSelector('div[title="ExchangeEmail"] select');
$selectElement = new WebDriverSelect($driver->findElement($selectDiv));
$selectElement->selectByVisibleText('Off (optional)');
例如,要使用XPath:

$sel = $driver->findElements(WebDriverBy::xpath('//select'));
$select = new WebDriverSelect($sel);
$select->selectByVisibleText('Off (optional)');