我是自動化測試新手,現在我正在嘗試在下拉菜單中選擇值。據我了解,我的示例中有兩個下拉菜單,但缺乏經驗使得很難弄清楚如何解決這個問題。我現在正在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(); }
1 回答

慕哥9229398
TA貢獻1877條經驗 獲得超6個贊
s.selectByValue("AMD");
選擇/取消選擇“值”屬性與指定參數匹配的選項。更正了您的代碼。希望有所幫助。如果沒有,請粘貼錯誤消息
添加回答
舉報
0/150
提交
取消