如何通过硒webdriver中的sendKeys传递变量? [英] how to pass a variable through sendKeys in selenium webdriver?

查看:449
本文介绍了如何通过硒webdriver中的sendKeys传递变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在下面的程序中通过sendKeys传递float变量'f',有人可以让我知道吗?到目前为止,它正在抛出

I want to pass the float variable 'f' through sendKeys in the below program.Can someone please let me know the same? As of now, it is throwing

"WebElement类型的方法sendKeys(CharSequence ...)不适用于参数".

"The method sendKeys(CharSequence...) in the type WebElement is not applicable for the arguments ".

代码:

public static String isEditable(String s1) {
    f=Float.parseFloat(s1);
    System.out.println(f);

    boolean bool=webDriver.findElement(By.xpath("expression")).isEnabled();
    if(bool) {
        if((f<0) || (f>6)) {
            error="Value must be between 0.00% and 6.00%";
            System.out.println(error);
        } else {
            webDriver.findElement(By.xpath(""expression")).sendKeys(f);
        }
    } else {
        error="Please enter a valid Number";
    }
    return error;
}

推荐答案

将浮点数转换为字符串:

Convert the float to a string:

webDriver.findElement(By.xpath("...")).sendKeys(Float.toString(f));

这篇关于如何通过硒webdriver中的sendKeys传递变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆