简体   繁体   English

SelectElement对象在Selenium C#中返回null

[英]SelectElement object returns null in Selenium C#

I am using Selenium with C# and when trying to access and select a value from the dropdown, it's not working. 我在C#中使用Selenium,当尝试从下拉列表中访问并选择一个值时,它不起作用。

I tried to debug using breakpoint, when I move cursor on object of SelectElement class object, it's showing null. 我尝试使用断点进行调试,当我将光标移到SelectElement类对象的对象上时,它显示为null。

But I know everything is correct. 但我知道一切正确。 whether we use id, name or xpath to locate the element. 是否使用id,name或xpath定位元素。

I am using chromedriver. 我正在使用chromedriver。

SelectElement ss = new SelectElement(driver.FindElement(By.Id("customer"))); 

I'm not sure what you are trying to select. 我不确定您要选择什么。 If you are trying to select a drop down, then you can use this. 如果您要选择一个下拉菜单,则可以使用它。

var customer = driver.FindElement(By.Id("customer"));
var selectElement = new SelectElement(customer);
selectElement.SelectByValue("customerType"); 

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

相关问题 带有 Selenium 的 C#:当前上下文中不存在“SelectElement” - C# with Selenium: "SelectElement" does not exist in the current context 在 selenium c# 中找不到类型或命名空间 SelectElement - The type or namespace SelectElement could not be found in selenium c# XPath 的 C# Selenium findElements 返回 null - C# Selenium findElements by XPath returns null Selenium:Firefox驱动程序,在C#中使用SelectElement从下拉列表中选择一项无法正常工作 - Selenium : Firefox Driver, Selecting an item from a dropdown using SelectElement in c# not working correctly 我可以将 map 2 个元素(SelectElement 和 WebElement)合并为一个元素,在 Selenium 中有多个 xpath 吗? C# - Can I map 2 elements (SelectElement and WebElement) into one element with multiple xpath in Selenium? C# C# 反序列化器返回空对象 - C# deserializer returns null object Selenium 2.39中的SelectElement失败 - SelectElement in Selenium 2.39 fails C#ManagementObjectSearcher对象容器为打印机返回null - C# ManagementObjectSearcher object container returns null for printers C# JsonConvert.DeserializeObject<dynamic> 返回 null object</dynamic> - C# JsonConvert.DeserializeObject<dynamic> returns a null object 无法在Selenium中将TransparentProxy强制转换为SelectElement - Unable to cast TransparentProxy to SelectElement in Selenium
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM