Javascript 如果没有设置值,如何在下拉列表中选择选项(selenium webdriver js)

Javascript 如果没有设置值,如何在下拉列表中选择选项(selenium webdriver js),javascript,selenium-webdriver,Javascript,Selenium Webdriver,我在网站上有以下下拉列表: <select id="deliveryType"> <option value>Please select</option> <option value>No delivery</option> <option value>Delivery One</option> <option value>Delivery Two</option></select&

我在网站上有以下下拉列表:

<select id="deliveryType">
<option value>Please select</option>
<option value>No delivery</option>
<option value>Delivery One</option>
<option value>Delivery Two</option></select>

如果未设置值,我如何选择选项?我需要“无传递”,但“给我元素#2”这样的逻辑也可以工作?

您可以使用
By.xpath
选择器执行以下操作:

this.driver
  .findElement(By.css([id=deliveryType]))
  .findElement(By.xpath(option[2])).click();

您可以使用xpath,对吗?我最终找到了一个适合我->通过文本调用选项的解决方案,例如this.driver.findElement(by.xpath(//*[@id=“deliveryType”]/[option[text()='No delivery'))。单击()
this.driver
  .findElement(By.css([id=deliveryType]))
  .findElement(By.xpath(option[2])).click();