【发布时间】:2018-03-27 19:11:58
【问题描述】:
伙计们,我已经开始研究 selenium 网络驱动程序了。你可以假设我是初学者。目前,我在代码(C#)中实现隐式等待命令时遇到了困难。它没有按应有的方式工作,并且由于未找到 Element 而导致异常,但是当我添加“Thread.Sleep(3000) 时,代码可以完美执行。我一直在互联网上寻找解决方案,但无法解决问题。下面我提到了示例代码。
class Entrypoint
{
static void Main()
{
IWebDriver driver = new ChromeDriver();
**driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);**
driver.Navigate().GoToUrl("https://r1.netrevelation.com:8443/mcba-cms/pages/flight-transfer.cab");
driver.Manage().Window.Maximize();
driver.FindElement(By.Id("loginlink")).Click();
driver.FindElement(By.Id("headerSubView:inputUserName:input")).SendKeys("st001");
driver.FindElement(By.Id("headerSubView:inputPassword:input")).SendKeys("hello321" + Keys.Enter);
driver.FindElement(By.Id("dateOfFlight:input")).Click();**//This Step does not get Executed , it throws exception element not found.**
driver.FindElement(By.Id("ui-datepicker-div")).Click();
driver.FindElement(By.XPath(".//*[@id='ui-datepicker-div']/div/a[2]/span")).Click();
driver.FindElement(By.LinkText("28")).Click();
IWebElement Flightno = driver.FindElement(By.Id("selectedFlight:input"));
Flightno.SendKeys("BA901" + Keys.Enter);
IWebElement Flighttick = driver.FindElement(By.Id("flightTickImg"));
driver.Quit();
请注意,目前我不想使用显式等待,因为隐式将满足我的需要(如果它开始工作)。上面的代码以超音速运行,以某种方式设法登录到系统,但之后每次失败,原因是一旦发出登录请求,系统暂停 2-3 秒。请提供您在这方面的评论。
【问题讨论】:
标签: c# selenium webdriver wait implicit