带有 Eclipse IDE 的 Selenium Webdriver - 元素应该是 "select" 但实际上是 "span"
Selenium Webdriver with Eclipese IDE - Element should have been "select" but was "span"
我的应用程序有下拉菜单,我遇到了这个问题:
org.openqa.selenium.support.ui.UnexpectedTagNameException: 元素应该是“select”但是是“span”
enter code here
@Test
public void cadastrar_serviço_completo() throws InterruptedException {
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://erpforme-hml.alterdata.com.br/");
Thread.sleep(1000);
driver.findElement(By.id("email-login")).sendKeys("*****");
driver.findElement(By.xpath("//form/div[2]/div/input")).sendKeys("*****");
driver.findElement(By.xpath("//button[@id='login-passaporte']")).click();
Thread.sleep(10000);
driver.findElement(By.xpath("//conpass[@id='conpass-tag']/div/div/div")).click();
driver.findElement(By.id("koopon-cabecalho-navbar-cadastro")).click();
driver.findElement(By.id("koopon-cabecalho-navbar-cadastro-estoque-servicos")).click();
Thread.sleep(1000);
driver.findElement(By.id("koopon-produto-servicos-btn-novo")).click();
Thread.sleep(1000);
driver.findElement(By.id("koopon-servico-input-valor-unitario")).sendKeys("10");
WebElement element = driver.findElement(By.id("select2-koopon-servico-select-lista-
codigos-servico-container"));
Select combo = new Select(element);
combo.selectByIndex(2);**
enter image description here
它不是 select 它是一个跨度,它应该在一个循环中遍历两个跨度,用一些共同的属性捕获它们,这样 select 你需要的一些条件,如果你愿意的话。
对不起我的英语。
示例:
el= driver.find_elements_by_xpath("//span[contains(@class,'select2-election')]")
for span in el :
if span.text == 'xxxxx':
span.click()
UnexpectedTagNameException
通过时显示此异常
其下不是 Select 类型的 WebElement 的引用
检查给定元素是否确实是 SELECT 标记。如果不是,则抛出 UnexpectedTagNameException
。
因此,如果您只传递 select
id koopon-servico-select-lista-codigos-servico
,那么不要 select2-koopon-servico-select-lista-codigos-servico-container
采用跨度属性,这样异常就不会显示
WebElement element = driver.findElement(By.id("koopon-servico-select- lista-codigos-servico"));
Select combo = new Select(element);
combo.selectByIndex(2);
I hope the above statements will help you
我的应用程序有下拉菜单,我遇到了这个问题: org.openqa.selenium.support.ui.UnexpectedTagNameException: 元素应该是“select”但是是“span”
enter code here
@Test
public void cadastrar_serviço_completo() throws InterruptedException {
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://erpforme-hml.alterdata.com.br/");
Thread.sleep(1000);
driver.findElement(By.id("email-login")).sendKeys("*****");
driver.findElement(By.xpath("//form/div[2]/div/input")).sendKeys("*****");
driver.findElement(By.xpath("//button[@id='login-passaporte']")).click();
Thread.sleep(10000);
driver.findElement(By.xpath("//conpass[@id='conpass-tag']/div/div/div")).click();
driver.findElement(By.id("koopon-cabecalho-navbar-cadastro")).click();
driver.findElement(By.id("koopon-cabecalho-navbar-cadastro-estoque-servicos")).click();
Thread.sleep(1000);
driver.findElement(By.id("koopon-produto-servicos-btn-novo")).click();
Thread.sleep(1000);
driver.findElement(By.id("koopon-servico-input-valor-unitario")).sendKeys("10");
WebElement element = driver.findElement(By.id("select2-koopon-servico-select-lista-
codigos-servico-container"));
Select combo = new Select(element);
combo.selectByIndex(2);**
enter image description here
它不是 select 它是一个跨度,它应该在一个循环中遍历两个跨度,用一些共同的属性捕获它们,这样 select 你需要的一些条件,如果你愿意的话。
对不起我的英语。 示例:
el= driver.find_elements_by_xpath("//span[contains(@class,'select2-election')]")
for span in el :
if span.text == 'xxxxx':
span.click()
UnexpectedTagNameException
通过时显示此异常
其下不是 Select 类型的 WebElement 的引用
检查给定元素是否确实是 SELECT 标记。如果不是,则抛出 UnexpectedTagNameException
。
因此,如果您只传递 select
id koopon-servico-select-lista-codigos-servico
,那么不要 select2-koopon-servico-select-lista-codigos-servico-container
采用跨度属性,这样异常就不会显示
WebElement element = driver.findElement(By.id("koopon-servico-select- lista-codigos-servico"));
Select combo = new Select(element);
combo.selectByIndex(2);
I hope the above statements will help you