Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/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_Selenium_Selenium Webdriver_Xpath_Webdriver - Fatal编程技术网

Python 如何为多个标记和多个值唯一标识xpath

Python 如何为多个标记和多个值唯一标识xpath,python,selenium,selenium-webdriver,xpath,webdriver,Python,Selenium,Selenium Webdriver,Xpath,Webdriver,我有以下html: <div class=‘content active’> <div> <div class=‘var’> <div class=‘field var-field’> <label>Interface Name</label> <div class=‘ui input’>

我有以下html:

<div class=‘content active’>
    <div>
        <div class=‘var’>
            <div class=‘field var-field’>
                <label>Interface Name</label>
                <div class=‘ui input’>
                    <input type=‘input’ placeholder=‘.*’ value> ==$0
                </div>
            </div>
        </div>
    </div>
    <div>
        <div class=‘var’>
            <div class=‘field var-field’>
                <label>Neighbor Id</label>
                <div class=‘ui input’>
                    <input type=‘input’ placeholder=‘.*’ value> ==$0
                </div>
            </div>
        </div>
    </div>
</div>
我需要将文本发送到带有标签的文本框:Interface Name。 是否有一种方法可以唯一地编写xpath以将文本发送到文本框。 请注意,唯一标识的方法是wrt标签。标记中的其他字段对于这两个字段都是相同的。 我试着使用和操作符。不走运。 请在此帮助我。

您可以使用此XPATH:-/*[text='Interface Name']/以下同级::div/input

尝试以下操作:

//label[text()='Interface Name']/following-sibling::div/child::input 
要向元素发送与标记相关的文本,可以创建如下函数:

def test_me(myText):
        driver.find_element_by_xpath("//label[.='" + myText + "']//following::div[1]/input").send_keys("hello")
test_me("Interface Name")
# or
test_me("Neighbor Id")
现在,您可以从脚本中的任意位置调用此函数,如下所示:

def test_me(myText):
        driver.find_element_by_xpath("//label[.='" + myText + "']//following::div[1]/input").send_keys("hello")
test_me("Interface Name")
# or
test_me("Neighbor Id")

输入类型='input'是什么意思?请向我们展示您尝试过的XPath。“有用吗?”卢茨·霍恩。连我都觉得很奇怪。我还没有开发这个网站。这在某种程度上起了作用。现在,我只需右键单击元素,然后复制xpath并给出*以获得最大可能的层次覆盖。i、 例如,xpath://*/div[2]/div[1]/div/div/div/input这显然有效,但我知道这是一个非常糟糕的解决方案。因此要求解决方案。工作就像一个符咒!!非常感谢!!