I need to confirm if selected value from combobox is correct and I have this code, but it just print the selected value. I want to compare with a text typed and if the selected value is the correct, the test should pass
I'm using Selenium with Java.
Select select = new Select(driver.findElement(By.id ("koopon-produto-select-produto-
especifico-calculos-icms")));
WebElement option = select.getFirstSelectedOption();
String defaultItem = option.getText();
System.out.println(defaultItem);
Can you check the below code, if it help
Select select = new Select(driver.findElement(By.id("koopon-produto-
select-produto-especifico-calculos-icms")));
String text = select.getFirstSelectedOption().getText();
String result = (text.equals(("test")))?"Pass":"Fail";
System.out.println(result);
import org.junit.Test;
import org.junit.Ignore;
import static org.junit.Assert.assertEquals;
public class TestJunit1 {
@Test
public void testSelectedCombobox() {
Select select = new Select(driver.findElement(By.id("koopon-produto-
select-produto-especifico-calculos-icms")));
String text = select.getFirstSelectedOption().getText();
assertEquals("expectedText", text);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.