如何单击只有类名Selenium的单选按钮

本文关键字:Selenium 单选按钮 何单击 单击 | 更新日期: 2023-09-27 18:13:03

我正在尝试点击这个单选按钮。

 <form id = "co-payment-form" class = "payment" action ="">
    <dt>
    <label class="radio" for="p_method_checkoutdotcom">
    <span class="radio__span">
    <i class="radio__icon"></i>
    </span>
    <span class="radio__title">Credit Card </span>
    </label>
    </dt>

我用代码瞄准它:

IWebElement creditcarradio = driver.FindElement(By.ClassName("radio__span"));

我得到错误:

类型为"OpenQA.Selenium"的未处理异常。WebDriverException'发生在WebDriver.dll中。元素在点(297.3999938964844,302.5)不可点击。其他元素将收到点击:<div class="loader loader--white-transparent loader--fixed"></div>

注意,该组中还有其他几个单选按钮。要查看它,只需填写此页面https://shop.adidas.ae/en/checkout/onepage/,直到您到达信用卡,Paypal或送货单选按钮

谢谢你的帮助

如何单击只有类名Selenium的单选按钮

根据错误描述,当您尝试单击该元素时,该元素上方会显示一个"loader"覆盖。等待元素成为可点击的,然后执行点击:

IWebElement element = new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(ExpectedConditions.ElementToBeClickable(By.ClassName("radio__span")));
element.Click();

尝试使用Actions。移动到该元素,然后触发点击。它应该能奏效。

像这样:在java中Actions clickOnRadioButton = new Actions(driver);clickOnRadioButton.moveToElement (driver.findElement (By.cssSelector("i.radio__icon")).click () .build () .perform ();