【发布时间】:2018-09-26 02:58:50
【问题描述】:
我想检查文本框和按钮,请帮助我。我想对文本框使用 sendkeys 功能。
HTML 代码:
<!DOCTYPE html>
<html>
<body>
<h2>HTML Forms</h2>
<form action="/action_page.php">
First name:
<br>
<input type="text" id="username">
<br> Last name:
<br>
<input type="text" id="username">
<br>
<br>
<input type="submit" value="Submit">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page called "/action_page.php".</p>
【问题讨论】:
-
向我们展示您的尝试?
-
尝试 //input[@id='username'] 用于文本框和 //input[@type='submit'] 用于按钮
-
@Mankeomorakort,但两个 textboxex 具有相同的属性,即 id=username 所以我如何检查第二个文本框
-
你可以通过索引找到元素://input[@id='username'][1]
标签: selenium selenium-webdriver xpath css-selectors webdriver