저는 자동화 테스트를 처음 접했고 지금은 드롭 다운 메뉴에서 값을 선택하려고합니다. 내 예에는 두 가지 드롭 다운이 있지만 경험이 부족 하여이 문제를 해결하는 방법을 파악하기가 어렵습니다. 나는 지금 https://www.spicejet.com/ 에서 일하고 있는데 내가하고 싶은 것은 성인을 클릭 한 후 승객을 선택하고 얼마나 많은 성인이되어야하는지 설정하는 것입니다.
드롭 다운을 선택하는 방법에 대한 비디오를 몇 개보고 있었지만, 간단한 드라이버를 사용하고 다른 클릭을 사용하여 선택 개체를 만들고 사용하도록 제안하는 사람은 거의 없습니다. 오류 때문에 작성된 코드가 많지 않습니다. 또한 새로운 개체를 만들고 드라이버 개체를 그에게 전달하고 작업을 수행한다는 것을 이해하면서 '선택'으로 길을 잃은 느낌?
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
public class dropdown {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.spicejet.com/"); // URL in the browser
driver.manage().window().maximize(); // Maximize the browser
Select s = new Select(driver.findElement(By.id("ctl00_mainContent_ddl_originStation1")));
s.selectByValue("2");
}
}
이것은 작동합니다->
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
public class dropdown {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.spicejet.com/"); // URL in the browser
driver.manage().window().maximize(); // Maximize the browser
// Get specific area to save it as variable and check it later if we are in right web page
String verifyPage = driver.findElement(By.xpath("//span[contains(text(),'Flights')]")).getText();
// Check it with IF
if (verifyPage.contentEquals("Flights")) {
System.out.println("[1] You are IN the right page.");
} else {
System.out.println("[2] You are NOT in the right page.");
}
driver.findElement(By.xpath("//div[@id='divpaxinfo']")).click();
Select dropdown = new Select(driver.findElement(By.xpath("//select[@id='ctl00_mainContent_ddl_Adult']")));
dropdown.selectByIndex(1);
}
}
s.selectByValue("AMD");
"값"속성이 지정된 매개 변수와 일치하는 옵션을 선택 / 선택 취소합니다. 코드를 수정했습니다.이 도움을 바랍니다. 그렇지 않은 경우 오류 메시지를 붙여 넣으십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다