我在网站:https://www.mister-auto.com/的"En sélectionnant mon véhicule“部分,我想选择一个品牌‘标致’,型号'107 [06/2005‘和汽车发动机'1.0 (68Cv),我尝试了这个品牌,但不起作用:
Select option = new Select(driver.findElement(By.xpath("/div[@class='dropdown'][1]/select[@class='form-control col-xs-12 ng-pristine ng-valid ng-not-empty ng-touched']")));
option.selectByVisibleText("Peugeot");知道为什么吗?
干杯。
发布于 2018-08-07 22:39:08
这应该是可行的:
WebElement element=driver.findElement(By.xpath("//select[@ng-model='brand_id']"));
Select option=new Select(element);
option.selectByValue("88");现在,如果您必须在标致的后续下拉列表中单击模型1007,则需要使用如下所示的JavascriptExecutor。这是因为它是一个optgroup元素,而在Select类中还没有optgroup元素。
WebElement element2=driver.findElement(By.xpath("//select[@ng-model='model_id']"));
element2.click();
WebElement element1=driver.findElement(By.xpath("//select[@ng-model='model_id']/optgroup[contains(@label,'1007')]"));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", element1);https://stackoverflow.com/questions/51729234
复制相似问题