我需要从下面的下拉菜单中选择一个元素。如何使用Selenium选择下拉菜单选项值 - Python
<select class="chosen" id="fruitType" name="fruitType">
<option value="">Select</option>
<option value="1">jumbo fruit 1</option>
<option value="2">jumbo fruit 2</option>
<option value="3">jumbo fruit 3</option>
<option value="4">jumbo fruit 4</option>
<option value="5">jumbo fruit 5</option>
<option value="8">jumbo fruit 6</option>
</select>
我已经使用这个代码试过,
driver = webdriver.Firefox()
driver.find_element_by_xpath("//select[@name='fruitType']/option[text()='jumbo fruit 4']").click()
但它返回我的错误。 我该怎么做才能做到这一点。
对于这个答案,我收到以下错误 driver.find_element_by_id(“fruitType”)。sendKeys(“jumbo fruit 4”); AttributeError:'WebElement'对象没有属性'sendKeys' – 404
对不起,请使用send_keys,我是表单java,所以这是一个错字错误,我也更新了python的sendkeys –
所以它就像select = Select(driver.find_element_by_xpath (“// select [@ id ='fruitType'and @ class ='selected']”)) driver.find_element_by_id(“fruitType”)。send_keys(“jumbo fruit 4”); – 404