亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我如何需要在下拉菜單中正確選擇項目?

我如何需要在下拉菜單中正確選擇項目?

拉丁的傳說 2024-01-28 16:06:05
我是自動化測試新手,現在我正在嘗試在下拉菜單中選擇值。據我了解,我的示例中有兩個下拉菜單,但缺乏經驗使得很難弄清楚如何解決這個問題。我現在正在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");

選擇/取消選擇“值”屬性與指定參數匹配的選項。更正了您的代碼。希望有所幫助。如果沒有,請粘貼錯誤消息


查看完整回答
反對 回復 2024-01-28
  • 1 回答
  • 0 關注
  • 168 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號