【发布时间】:2017-11-06 10:03:39
【问题描述】:
所以目前我有这个代码:
//WebElement VariableName is to declare the name of the WebElement
//String Id is the Id of the element that you want to send values to
//String valuesToAddIn is the value that you want to enter into the webpage
//String stringNameToCompareLater is the variable to store the values of the input, that you just entered.
public void AddInValueAndCompareString(WebElement VariableName ,String Id , String valuesToAddIn, String stringNameToCompareLater)
{
VariableName = driver.findElement(By.id(Id));
VariableName.sendKeys(valuesToAddIn);
EnsureUserInputByID(Id);
stringNameToCompareLater = VariableName.getText();
}
我想做的是获取我刚刚使用 selenium 输入的字符串并将其存储在一个变量中。
但是,如果您要为代码的每一部分添加这些行,将会非常麻烦。
所以我上面代码的实现如下:
AddInValueAndCompareString(CourseFeePaid,"courseFeePaid","123.90","courseFeePaidCompare");
但是,CourseFeePaid 实际上给了我
的错误CourseFeePaid cannot be resolved to a variable
是我无法在参数中声明WebElement的名称,还是代码中存在任何其他错误。
我想要得到的最终成果是:
- 值被添加到文本框中
- 值存储在变量中,以便以后进行比较。
【问题讨论】: