简体   繁体   English

如何从 selenium webdriver 的下拉列表中选择一个选项。 该元素不是“选择”元素

[英]How to select an option from drop down in selenium webdriver. The element is not a 'select' element

<svg viewBox="0 0 24 24" style="display: inline-block; fill: rgb(224, 224, 224); height: 24px; width: 24px; transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; position: absolute; right: 0px; top: 22px; -webkit-user-select: none;"><path d="M7 10l5 5 5-5z"></path></svg>

<path d="M7 10l5 5 5-5z"></path>

I've attempted, using as a container, using the action class to hover over, using the select class but none seem to be working.我尝试过,用作容器,使用操作类悬停,使用选择类,但似乎都没有工作。

If the element is not a select element then it's still a WebElement.如果元素不是选择元素,那么它仍然是一个 WebElement。 Display the options and find the xpath for the option and if you need to select a particular one, use the find by text as follows.显示选项并找到该选项的 xpath,如果您需要选择一个特定的选项,请使用按文本查找,如下所示。 You may need to have a wait in place to wait for the option to display.您可能需要等待一段时间才能显示该选项。

Example: 1. Click on the drop down element to display the list of items.示例: 1. 单击下拉元素以显示项目列表。 2. Use the following to find the option and then select it 2.使用下面的找到该选项,然后选择它

WebElement yourElement = driver.findElement(By.xpath("//*[contains(text(),'THE OPTION TEXT YOURE LOOKING FOR')]"));
yourElement.click();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Java从Selenium WebDriver中的不可见下拉元素中选择选项 - How to select option from invisible drop-down element in Selenium WebDriver using Java Selenium WebDriver。 从div列表中选择元素 - Selenium WebDriver. Select element from div list 如何从下拉列表中随机选择Selenium Webdriver(java)中的元素在html中? - How to select element from drop down Randomly in Selenium webdriver (java) drop down is in html? 无法从Selenium Webdriver的下拉列表中选择隐藏元素 - Not able to select hidden element from drop down list in Selenium Webdriver 如何使用selenium webdriver java从城市字段的GoIbibo中的自动选择下拉列表中选择一个元素 - how to select an element from autoselect drop down in GoIbibo from city field using selenium webdriver java Selenium WebDriver:无法使用webdriver从下拉列表中选择元素 - Selenium WebDriver: Not able to select the element from the drop down list using webdriver 无法使用Java从Selenium Webdriver的下拉列表中选择选项 - Not able to select option from drop down list in selenium webdriver with java 如何使用带有Java的Selenium WebDriver从下拉列表中选择一个选项? - How to select an option from a drop-down using Selenium WebDriver with Java? 无法使用 webdriver 中的操作 class 从下拉列表中 select 元素 - Unable to select element from drop down using Actions class in webdriver selenium2:Selenium WebDriver:从“图像下拉”列表框中选择一个选项 - selenium2:Selenium WebDriver : Select one option from Image Drop Down list Box
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM