0

So currently I have this codes:

      //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();
      }

What I would like to do, is to get the string that I have just entered using selenium and store it in a variable.

However, it is going to be very troublesome, if you were to add in these lines for every part of the code.

So my implementation of the above code is as follows:

AddInValueAndCompareString(CourseFeePaid,"courseFeePaid","123.90","courseFeePaidCompare");

However, the CourseFeePaid is actually giving me the error of

CourseFeePaid cannot be resolved to a variable

So is it that I cannot declare the name of the WebElement in a parameter, or is there any other errors in the code.

The ultimate deliverable that i want to get is:

  1. The values are added into the textboxes
  2. The values are stored inside of a variable, so as to do comparison later.
Lan Yung Lee
  • 31
  • 1
  • 10

1 Answers1

0

You can look here to see the same problem Java, "Variable name" cannot be resolved to a variable I guess you have problem not in the method 'AddInValueAndCompareString', but when you call this method. Your implementation has too much parameters: 1. What the sense to pass WebElement VariableName and in the first row call VariableName = driver.findElement(By.id(Id)); You can just remove first parameter and first row will be WebElement VariableName = driver.findElement(By.id(Id)); 2. You pass as parameter stringNameToCompareLater, but again in the 4-th row you have an assignment stringNameToCompareLater = VariableName.getText(); why not remove stringNameToCompareLater from parameters and have String stringNameToCompareLater = VariableName.getText(); in the 4-th row. So you pass two variables with values, but never use them, they in fact local variables. That does not make sense.

And yes, you can getentered text. But you will need see where it's stored after typing. E.g. it could be in 'value' attribute, so you can get it like this: String enteredtext = VariableName.getAttribute("value"); But it depends on page, just keep in mind, that VariableName.getText(); not always works

SerhiiBond
  • 247
  • 3
  • 8