简体   繁体   中英

Select from tag type - input dropdown with selenium C# webdriver

掉落

How can i get element from below dropdwon, i have used Select command to select dropdowns, but here type is input.

<input class="tp-select-input" autocapitalize="none" autocorrect="off" autocomplete="off" spellcheck="false" data-testid="register-country" value="">

As dropdown you want to select value from is not a select type tag, Selenium Select method wont work on it. You have to follow below steps:

  1. Click on Dropdown / or Arrow
  2. Locate webelement you want to select from dropdown
  3. Use java script executioner to click the option you want to select

Since you have not given complete HTML, below is the dummy code:

driver.FindElement(By.XPath("//input[@data-testid='register-country']")).Click() // Click on dropdown
 IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;
 executor.ExecuteScript("arguments[0].click();", driver.FindElement(By.XPath("//*[text()='Austria']"))); //You can give more accurate xpath for country you want to select based on other HTML attributes

You can also try with below code

IWebElement element = driver.FindElement(By.ClassName("tp-select-input")); driver.FindElement(By.XPath("//span[text()='Australia']")); element.SendKeys(OpenQA.Selenium.Keys.Down); element.SendKeys(OpenQA.Selenium.Keys.Return);

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