【问题标题】:How to locate the First name and Last name text fields?如何找到名字和姓氏文本字段?
【发布时间】: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'] 用于按钮
  • 请阅读此网址:guru99.com/xpath-selenium.html
  • @Mankeomorakort,但两个 textboxex 具有相同的属性,即 id=username 所以我如何检查第二个文本框
  • 你可以通过索引找到元素://input[@id='username'][1]

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


【解决方案1】:

要将字符序列发送到First nameLast name字段,您可以使用以下解决方案:

  • 名字:

    • 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] 
      

【讨论】:

  • 请停止编辑问题标题以在某处添加“按”。它使每个问题听起来都像是由英语不好的人提出的。
猜你喜欢
  • 1970-01-01
  • 2016-02-22
  • 1970-01-01
  • 1970-01-01
  • 2021-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多