繁体   English   中英

Selenium Webdriver单选按钮问题

[英]Selenium Webdriver radio button issue

我导出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选择它。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM