Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 选择给定标签的xpath输入_Python_Xpath_Selenium Webdriver - Fatal编程技术网

Python 选择给定标签的xpath输入

Python 选择给定标签的xpath输入,python,xpath,selenium-webdriver,Python,Xpath,Selenium Webdriver,因此,我通常使用driver.find_element_by_xpath'//input[@id=/*[containstext,User Name]/@for]'将信息输入文本框,但这对以下代码不起作用: <div class="form-group text-entry required "> <div class="label-set" id="answerTextBox-30918642">Primary User Name (First and Last N

因此,我通常使用driver.find_element_by_xpath'//input[@id=/*[containstext,User Name]/@for]'将信息输入文本框,但这对以下代码不起作用:

<div class="form-group text-entry required ">
  <div class="label-set" id="answerTextBox-30918642">Primary User Name (First and Last Name)</div>
  <div class="group-set" role="group" aria-labelledby="answerTextBox-30918642">
    <input id="pageResponse_Responses_Index" name="pageResponse.Responses.Index" type="hidden" value="fta30918642">
    <input class="freeTextAnswerId form-control" id="pageResponse_Responses_fta30918642__FreeTextAnswerId" name="pageResponse.Responses[fta30918642].FreeTextAnswerId" type="hidden" value="30918642">
    <label for="answerTextBox-30918642-free" class="sr-only">Write-In Answer</label>
    <input class="form-control free-text" id="answerTextBox-30918642-free" name="pageResponse.Responses[fta30918642].FreeText" type="text" value="">
  </div>
</div>

但到目前为止,我尝试过的方法都没有奏效。这可以找到包含标签driver的元素。通过_xpath/*[containstext,'User Name']查找_element _,但我的问题是选择要向其发送密钥的输入。

因此我能够让它工作。Santhosh的建议:


//*[containstext,\User Name\]/../div//input[@class='form-control free text']

您可以将XPath简化为

//div[contains(.,'User Name')]/following::input[@type='text']
这个

以下轴表示上下文节点之后出现的所有节点,但任何子体、属性和命名空间节点除外


其他输入是隐藏的,因此指定@type='text'将只找到您想要的输入。

//div//input[@class='form-control-free-text']对您有用吗?请阅读原因。粘贴代码并正确格式化。@JeffC执行此操作help@Jake一些我修好了。我通常在发布HTML时使用HTML美化工具。
//div[contains(.,'User Name')]/following::input[@type='text']