简体   繁体   中英

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.

I tried to debug using breakpoint, when I move cursor on object of SelectElement class object, it's showing null.

But I know everything is correct. whether we use id, name or xpath to locate the element.

I am using 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"); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM