0

enter image description here

I am writing code to get state value from the drop-down and depending upon the state calculating the tax rate. I am using switch case statement to define the tax rate for each state. I want to use selected state in the switch case statement, how I can do it.

Here is my code:

Select stateSelect = new Select(driver.findElement(By.id("ddlState")));    
stateSelect.selectByVisibleText(state);

double dl; 
double taxrate =0; 
switch(*****) // What I can write here inorder to get selected state
{ 
    case "British Columbia":
         taxrate = 0.05;
         break; 

    case "Alberta":
         taxrate = 0.10;
         break; 
        // And so on.....
} 
taxprice= pprice*taxrate; 
1
  • String selectedOption = stateSelect.getFirstSelectedOption().getText(); return selected option but I don't understand why you want to set option and then get option...
    – kotoj
    Jun 24 '16 at 0:10
1

'state' variable holds the name of the state you are about to select. Simply use this variable in switch statement.

switch(state){
  //cases
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.