Click()方法在使用C#Selenium IDE时不起作用

Click()方法在使用C#Selenium IDE时不起作用,c#,selenium,onclick,click,C#,Selenium,Onclick,Click,我正在尝试从c#执行selenium测试。我已经在selenium IDE上记录了测试,并使用IDE工具验证了它的有效性。该测试是一个简单的概念证明。浏览到联合航空公司的网站,在他们的搜索小部件上输入一些航班信息并调用搜索。当我运行该项目时,除了单击搜索按钮不会像使用Selenium IDE时那样调用单击之外,其他一切都正常 没有抛出错误的非工作行 driver.FindElement(By.Id("ctl00_ContentInfo_Booking1_btnSearchFlight")).C

我正在尝试从c#执行selenium测试。我已经在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;

问题是页面上有两个
ctl00\u ContentInfo\u Booking1\u btnSearchFlight
。第一个是
div
,第二个是要单击的按钮

请尝试以下方法:

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

@多谢你的建议,我确实试过了,但也得到了同样的结果。在执行这些操作之前,请尝试添加Wait()或Sleep()。有时,上一次单击()会进行一些处理并禁用UI,因此请等待一段时间,然后尝试执行下一个操作。@bit我尝试了五秒钟的线程睡眠。在点击之前,我还删除了任何其他点击事件。顺便提一句,很好的建议我不知道为什么这样做不起作用。另一个解决办法是调用JS方法wiried to the button Click()。另一个解决办法是尝试单击父元素。。代码看起来类似于driver.findelelement(By.XPath(“/*[@id='ctl00\u ContentInfo\u Booking1\u btnsearchfright']/祖先::div[1]”);