【发布时间】:2018-11-30 11:45:24
【问题描述】:
我不熟悉在我的代码中使用显式等待。在我的代码中,我以前有隐式等待,但现在我想使用显式等待。我尝试使用与隐式等待相同的概念,但我的SelectElementFromDropDown 出现异常。该错误是专门用“国家”和“货币”引发的
我已经注释掉了我之前工作的代码。
我已经按照这个例子进行了
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
IWebElement button = wait.Until(ExpectedConditions.ElementExists(By.Id("someId"));
/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Interactions;
using System.Threading;
namespace Exercise1
{
class test3
{
static void Main(string[] args)
{
IWebDriver webDriver = new ChromeDriver();
webDriver.Navigate().GoToUrl("http://www.asos.com/men/");
webDriver.Manage().Window.Maximize();
webDriver.FindElement(By.XPath(".//button[@data-testid='country-selector-btn']")).Click();
WebDriverWait wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(5));
IWebElement button = wait.Until(ExpectedConditions.ElementExists(By.Id("country")));
SelectElementFromDropDown(country, "India");
//webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
//IWebElement country = webDriver.FindElement(By.Id("country"));
//SelectElementFromDropDown(country, "India");
WebDriverWait wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(5));
IWebElement element = wait.Until(ExpectedConditions.ElementExists(By.Id("currency")));
SelectElementFromDropDown(currency, "$ USD");
//IWebElement currency = webDriver.FindElement(By.Id("currency"));
//SelectElementFromDropDown(currency, "$ USD");
webDriver.FindElement(By.XPath(".//button[@data-testid='save-country-button']")).Click();
webDriver.Quit();
}
private static void SelectElementFromDropDown(IWebElement ele, string text)
{
SelectElement select = new SelectElement(ele);
select.SelectByText(text);
}
}
}
【问题讨论】:
-
错误是什么?
TimeoutException? -
未指定国家和货币值。
标签: c# selenium selenium-webdriver