C# Selenium Webdriver单选按钮问题

C# Selenium Webdriver单选按钮问题,c#,asp.net,selenium,selenium-webdriver,C#,Asp.net,Selenium,Selenium Webdriver,我导出Selenium IDE代码,以便在Selenium Web驱动程序中进行自动测试。代码执行正确,但在单选按钮上它停止并在Selenium Webdriver上生成错误。请指导我在webdriver上成功执行单选按钮 我的代码是: driver.FindElement(By.Id("ContentPlaceHolder1_ucTriple_rptOffers_AddToCartButton_0")).Click(); System.Threading.Thread

我导出Selenium IDE代码,以便在Selenium Web驱动程序中进行自动测试。代码执行正确,但在单选按钮上它停止并在Selenium Webdriver上生成错误。请指导我在webdriver上成功执行单选按钮

我的代码是:

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

            System.Threading.Thread.Sleep(20000);  
            driver.FindElement(By.Id("rptShoppingServiceGroup_dlAddons_1_ctl03_0_1_0")).Click();
            driver.FindElement(By.Id("rptShoppingServiceGroup_dlAddons_1_ctl03_1_3_1")).Click();
            driver.FindElement(By.Id("rptShoppingServiceGroup_dlDevices_1_ctl03_0_1_0")).Click();
            driver.FindElement(By.Id("rptShoppingServiceGroup_dlAddons_2_ctl01_2")).Click();
            driver.FindElement(By.Id("rptShoppingServiceGroup_dlDevices_2_ctl03_0_2_0")).Click();
            driver.FindElement(By.Id("rptShoppingServiceGroup_dlDevices_2_ctl03_0_0_0")).Click();
            driver.FindElement(By.Id("SubmitButton")).Click();
发现的错误是:

Unable to locate element: {"method":"id","selector":"rptShoppingServiceGroup_dlAddons_1_ctl03_0_1_0"}

如何从中删除错误并成功执行。

页面中的单选按钮似乎是动态生成的。然后,有两个可能的错误原因:

  • 当您尝试单击收音机时,它不存在。确保已执行了使该单选按钮出现的先前步骤
  • 生成的单选按钮具有不同的名称(名称中的数字可能不同)。尝试使用xpath而不是确切的id来选择它

我的建议是在没有选择指令的情况下运行代码,并且不要退出驱动程序(即不要关闭浏览器),这样您就可以检查结果页面,并查看是否显示了单选按钮及其实际名称。

单选按钮是否存在于帧内?在导出的脚本中,您能看到任何已注释掉的框架语句吗?非常感谢您的建议