Selenium webdriver 下拉组合框中不存在断言给定文本

Selenium webdriver 下拉组合框中不存在断言给定文本,selenium-webdriver,Selenium Webdriver,我必须自动实现这样一个场景:我得到了我存储的名字和电子邮件地址,然后我需要用下拉框断言那个值,它不存在 这是我的网页的HTML代码 <select id="Customer" name="Customer" class="valid"> <option value="raj777@gmail.com">123123123 (raj777@gmail.com)</option> </select> 提前感谢 遵循以下流程: 获取下拉列表中每个元素

我必须自动实现这样一个场景:我得到了我存储的名字和电子邮件地址,然后我需要用下拉框断言那个值,它不存在

这是我的网页的HTML代码

<select id="Customer" name="Customer" class="valid">
<option value="raj777@gmail.com">123123123  (raj777@gmail.com)</option>
</select>

提前感谢

遵循以下流程:

  • 获取下拉列表中每个元素的文本(“选项”元素)
  • 选择字符串列表或数组中的值
  • 查看包含您的姓名和邮件id值的列表或数组
  • 或者,如果您只想断言,则在for数组或列表的每个循环中: 加t

  • 他在try-catch块中断言语句
  • 在catch块中,每次执行到此块时,增加一个整数
  • 在fr每个循环之后,检查整数值是否等于yor列表或数组大小
  • 第一个场景的代码示例:

        driver.findElement(By.cssSelector(".trb_outfit_sponsorship_logo_img"))
            .click();
        System.out.println(dri.findElement(
            By.cssSelector(".trb_outfit_sponsorship_logo_img")).getSize());
        List<WebElement> dropDownValues = dri.findElements(By
            .xpath("//select[@id='Customer']"));
        ArrayList<String> dropDownValuesasText = null;
        for (WebElement eachValue : dropDownValues) {
            dropDownValuesasText.add(eachValue.getText());
        }
    //  boolean result = dropDownValuesasText.contains("Your FirstName & Email value");
        //It will pass if your value is present in drop down
        assertNotEquals(dropDownValuesasText.contains("Your FirstName & Email value"), true);
    
    driver.findElement(由.cssSelector(“.trb\u装备\u赞助\u标志\u img”))
    。单击();
    System.out.println(dri.findElement(
    通过.cssSelector(“.trb_detage_赞助商_logo_img”)).getSize();
    列表下拉值=dri.findElements(按
    .xpath(“//选择[@id='Customer']”);
    ArrayList dropDownValuesasText=null;
    for(WebElement eachValue:dropDownValues){
    dropdownValuesText.add(eachValue.getText());
    }
    //布尔结果=DropDownValuesText.contains(“您的名字和电子邮件值”);
    //如果您的值出现在下拉列表中,则它将通过
    assertNotEquals(dropDownValuesasText.contains(“您的名字和电子邮件值”),true);
    
        driver.findElement(By.cssSelector(".trb_outfit_sponsorship_logo_img"))
            .click();
        System.out.println(dri.findElement(
            By.cssSelector(".trb_outfit_sponsorship_logo_img")).getSize());
        List<WebElement> dropDownValues = dri.findElements(By
            .xpath("//select[@id='Customer']"));
        ArrayList<String> dropDownValuesasText = null;
        for (WebElement eachValue : dropDownValues) {
            dropDownValuesasText.add(eachValue.getText());
        }
    //  boolean result = dropDownValuesasText.contains("Your FirstName & Email value");
        //It will pass if your value is present in drop down
        assertNotEquals(dropDownValuesasText.contains("Your FirstName & Email value"), true);