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

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.

主站蜘蛛池模板: 壶关县| 获嘉县| 简阳市| 张家港市| 鹤山市| 五家渠市| 布拖县| 淮安市| 秦皇岛市| 贵定县| 旌德县| 安仁县| 精河县| 敦化市| 大姚县| 嘉定区| 三门县| 南华县| 东乡族自治县| 怀仁县| 靖州| 都昌县| 丰都县| 德钦县| 和政县| 定日县| 嘉义市| 余庆县| 平度市| 双流县| 阿鲁科尔沁旗| 德化县| 桦南县| 灵丘县| 那坡县| 衡阳县| 葫芦岛市| 武功县| 凉城县| 张家界市| 汉沽区|