Get all Elements in a Form

后端 未结 4 1314
渐次进展
渐次进展 2021-02-02 14:56

I would like to use Selenium to submit a form which contains several elements. For example:

4条回答
  •  清酒与你
    2021-02-02 15:20

    Store the form element in a variable, then use it as the search context to find the child elements:

    WebElement formElement = driver.findElement(By.name("something"));
    WebElement a = formElement.findElement(By.name("a"));
    WebElement b = formElement.findElement(By.name("b"));
    WebElement c = formElement.findElement(By.name("c"));
    
    a.sendKeys("first child element [a]");
    b.sendKeys("password");
    c.submit();
    

提交回复
热议问题