【问题标题】:Click() method not working using C# Selenium IDEClick() 方法无法使用 C# Selenium IDE
【发布时间】:2014-04-04 03:37:04
【问题描述】:

我正在尝试从 c# 执行硒测试。我已经在 selenium IDE 上记录了测试,并使用 IDE 工具验证了它的工作原理。该测试是一个简单的概念证明。浏览到联合航空公司的网站,在他们的搜索小部件上输入一些航班信息并调用搜索。当我运行该项目时,除了单击搜索按钮不会像使用 Selenium IDE 时那样调用单击之外,一切正常。

没有错误抛出的非工作线

 driver.FindElement(By.Id("ctl00_ContentInfo_Booking1_btnSearchFlight")).Click();

完整代码

driver = new FirefoxDriver();
baseURL = "http://www.united.com/";
verificationErrors = new StringBuilder();
enter code here
driver.Navigate().GoToUrl(baseURL + "/web/en-US/default.aspx?root=1");
driver.FindElement(By.Id("ctl00_ContentInfo_Booking1_Origin_txtOrigin")).Clear();
driver.FindElement(By.Id("ctl00_ContentInfo_Booking1_Origin_txtOrigin")).SendKeys("fort lauderdale, fl");
driver.FindElement(By.Id("ctl00_ContentInfo_Booking1_Destination_txtDestination")).Clear();
driver.FindElement(By.Id("ctl00_ContentInfo_Booking1_Destination_txtDestination")).SendKeys("New York/Newark, NJ (EWR - Liberty)");
driver.FindElement(By.Id("ctl00_ContentInfo_Booking1_DepDateTime_Depdate_txtDptDate")).Click();
driver.FindElement(By.Id("ctl00_ContentInfo_Booking1_DepDateTime_Depdate_txtDptDate")).Clear();
driver.FindElement(By.Id("ctl00_ContentInfo_Booking1_DepDateTime_Depdate_txtDptDate")).SendKeys("4/7/2014");
driver.FindElement(By.Id("ctl00_ContentInfo_Booking1_RetDateTime_Retdate_txtRetDate")).Clear();
driver.FindElement(By.Id("ctl00_ContentInfo_Booking1_RetDateTime_Retdate_txtRetDate")).SendKeys("4/14/2014");
driver.FindElement(By.Id("ctl00_ContentInfo_Booking1_btnSearchFlight")).Click();


String test = driver.PageSource;

【问题讨论】:

  • @bit 感谢您的建议,我确实尝试过,但取得了相同的结果。
  • 在执行这些操作之前尝试添加 Wait() 或 Sleep()。有时,之前的 Click() 会进行一些处理并禁用 UI,因此请等待一段时间,然后尝试执行下一个操作..
  • @bit 我尝试了一个线程睡眠五秒钟。在相关点击之前,我还删除了任何其他点击事件。顺便说一句,很好的建议不知道为什么这不起作用。
  • 另一种出路可能是调用连接到按钮 Click() 的 JS 方法..
  • 另一种方法是尝试 Click() 父元素.. 代码看起来像 driver.FindElement(By.XPath("//*[@id='ctl00_ContentInfo_Booking1_btnSearchFlight']/祖先::div[1]")).Click();

标签: c# selenium onclick click


【解决方案1】:

问题是页面上有两个ctl00_ContentInfo_Booking1_btnSearchFlight。第一个是div,第二个是你要点击的按钮。

试试这个:

FindElement(By.CssSelector("input#ctl00_ContentInfo_Booking1_btnSearchFlight")).Click();

【讨论】:

    猜你喜欢
    • 2010-11-26
    • 1970-01-01
    • 2019-04-04
    • 1970-01-01
    • 1970-01-01
    • 2018-02-07
    • 1970-01-01
    • 1970-01-01
    • 2019-08-10
    相关资源
    最近更新 更多