官术网_书友最值得收藏!

The submit() method

The submit() action can be taken on a Form or on an element, which is inside a Form element. This is used to submit a form of a web page to the server hosting the web application. The API syntax for the submit() method is as follows:

void submit()

The preceding method doesn't take any input parameters and doesn't return anything. But a NoSuchElementException is thrown when this method is executed on a WebElement that is not present within the form.

Now, let's see a code example to submit the form on a Search page:                                       

@Test
public void elementSubmitExample() {
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys(Keys.chord(Keys.SHIFT,"phones"));
searchBox.submit();
}

In the preceding code, toward the end is where the Search form is submitted to the application servers using the submit() method. Now, try to execute the submit() method on an element, let's say the About link, which is not a part of any form. We should see NoSuchElementException is thrown. So, when you use the submit() method on a WebElement, make sure it is part of the Form element.

主站蜘蛛池模板: 南川市| 肥西县| 昌平区| 保山市| 克拉玛依市| 鄂托克旗| 张家川| 阜平县| 赤城县| 韩城市| 新和县| 汉中市| 新丰县| 安福县| 鹤壁市| 鸡东县| 玛沁县| 侯马市| 湛江市| 手游| 柳州市| 克东县| 嘉义县| 南丹县| 克山县| 英山县| 四平市| 潮安县| 丁青县| 黎城县| 绩溪县| 百色市| 定陶县| 公安县| 晋宁县| 阜平县| 翼城县| 木兰县| 凤台县| 高安市| 上栗县|