如何找到名字和姓氏文本字段?

时间:2018-09-25 04:28:40

标签: selenium selenium-webdriver xpath css-selectors webdriver

我想检查文本框和按钮,请帮助我。我想对文本框使用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>

1 个答案:

答案 0 :(得分:1)

要将字符序列发送到名字姓氏字段,您可以使用以下解决方案:

  • 名字:

    • CssSelector

      form[action='/action_page.php'] input:nth-of-type(1)
      
    • XPath

      //form[@action='/action_page.php']//following::input[1]
      
  • 姓氏:

    • CssSelector

      form[action='/action_page.php'] input:nth-of-type(2)
      
    • XPath

      //form[@action='/action_page.php']//following::input[2]