【问题标题】:BAD : need suggest on selenium using radio button select.have three radio buttons.need to select appropriate.but getting error坏:需要使用单选按钮选择硒建议。有三个单选按钮。需要选择适当的。但出现错误
【发布时间】:2016-02-21 07:31:34
【问题描述】:

我正在开发一个门户网站,我们可以在其中从三个单选按钮中选择凭证类型。它不工作:我收到一个错误。

import java.util.concurrent.TimeUnit;
import org.apache.log4j.Logger;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Vouchertest {

    public static void main(String[] args) {

        WebDriver driver=new FirefoxDriver();
            Logger log = Logger.getLogger("devpinoyLogger");
        driver.get("url");
            log.debug("entring username");
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.findElement(By.xpath("//*[@id='UserName']")).sendKeys("xoxo");
            log.debug("entering password");
        driver.findElement(By.xpath("//*[@id='Password']")).sendKeys("Password123");
            log.debug("Clicking login");
        driver.findElement(By.xpath("//*[@id='loginForm']/form/div[4]/div/input")).click();
        log.debug("Clicking voucher");
        driver.findElement(By.xpath("html/body/nav/div[2]/div[2]/ul/li[2]/a")).click();
        log.debug("Clicking create_voucher");
        driver.findElement(By.xpath("//*[@id='main']/a[1]")).click();
        **log.debug("Clicking voucher_type");
        driver.findElement(By.cssSelector("input[value='card']")).click();

    }

}

这里是 html 代码:

<input id="VoucherType" type="radio" value="Corporate" name="VoucherType">
<label for="Corporate_Certificate">Corporate Certificate</label>
<input id="VoucherType" type="radio" value="Card" name="VoucherType">
<label for="Gift_Card">Gift Card</label>
<input id="VoucherType" type="radio" value="Adv" name="VoucherType">
<label for="Advanced_Payment">Advanced Payment</label>

这是踪迹:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"css selector","selector":"input[value='card']"}
Command duration or timeout: 30.12 seconds

【问题讨论】:

    标签: java selenium button radio


    【解决方案1】:

    在您的 HTML 代码中,“Card”以大写字母开头,而在您的 Java 代码中,它是这样写的:“input[value='card']”

    【讨论】:

      【解决方案2】:

      我可以立即在您的 css 选择器中看到的一个问题是在 html 代码中,您的值为 Card(C 为大写),但在定位器中,您以简单的大小写方式传递值 卡片

      请尝试以下定位器:

      CSS 选择器:input[value='Card']

      Xpath : //input[@value='Card']

      如果这不起作用,请检查您是否在 iframe 中有这些单选按钮。如果是这样,您必须先切换到 iframe。

      【讨论】:

      • 非常感谢你们俩。它的工作。我只是看不到那个愚蠢的错误。
      猜你喜欢
      • 1970-01-01
      • 2020-10-15
      • 1970-01-01
      • 2011-08-14
      • 2019-09-29
      • 2017-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多