How to get option value of select element

后端 未结 6 1077
故里飘歌
故里飘歌 2021-01-03 23:40

I am trying to get the option value of a select element using Protractor. However, I\'m not able to find the option element.

HTML

&l         


        
6条回答
  •  耶瑟儿~
    2021-01-04 00:05

    Try using xPath:

    ptor.findElement(protractor.By.xpath('//select/option[1]'));

    You can use the same technique to choose an option by value:

    protractor.By.xpath('//select/option[text()="Option 2"]'));

    I've needed to do this for setting up forms where inputs are visible based on selected dropdowns, e.g.:

    makeFord = protractor.By.xpath('//select[@id="make"]/option[text()="Ford"]'));
    modelMustang = protractor.By.xpath('//select[@id="model"]/option[text()="Mustang"]'));
    makeFord.click();
    modelMustang.click();
    

提交回复
热议问题