[英]How to select from a dropdown with Selenium WebDriver 3.8 for C#
[英]Select from tag type - input dropdown with selenium C# webdriver
由於下拉列表中的 select 值不是 select 類型標簽,因此 Selenium Select 方法無法對其起作用。 您必須按照以下步驟操作:
由於您沒有給出完整的 HTML,下面是偽代碼:
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
您也可以嘗試使用以下代碼
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.