Xpath如何在两个兄弟节点之间查找元素,其中一个节点';t唯一属性

Xpath如何在两个兄弟节点之间查找元素,其中一个节点';t唯一属性,xpath,Xpath,我需要在具有给定文本的第一个同级xguielementtypeother和也具有文本的第二个同级xguielementtypeother之间找到同级xguielementtypecell,但在搜索时我们不知道该文本(所以我们假设它没有唯一的属性)。我试着这样写: //XCUIElementTypeCell/XCUIElementTypeStaticText[preceding::XCUIElementTypeOther[./XCUIElementTypeStaticText[@name="' +

我需要在具有给定文本的第一个同级
xguielementtypeother
和也具有文本的第二个同级
xguielementtypeother
之间找到同级
xguielementtypecell
,但在搜索时我们不知道该文本(所以我们假设它没有唯一的属性)。我试着这样写:

//XCUIElementTypeCell/XCUIElementTypeStaticText[preceding::XCUIElementTypeOther[./XCUIElementTypeStaticText[@name="' + text + '"]]][following::XCUIElementTypeOther[./XCUIElementTypeStaticText][1]]
但是它不起作用(查找第一个之后的所有同级
xguielementtypecell
),我不知道如何在xpath中定义。 我试图在已经提出的问题中找到答案,但尝试失败了


以下表达式应适用

//XCUIElementTypeOther[XCUIElementTypeStaticText/@name = 'your text here']/following-sibling::XCUIElementTypeOther[1]/preceding-sibling::XCUIElementTypeCell

下面的表达式应该有效

//XCUIElementTypeOther[XCUIElementTypeStaticText/@name = 'your text here']/following-sibling::XCUIElementTypeOther[1]/preceding-sibling::XCUIElementTypeCell

您应该能够使用一个子
xguielementtypestatictext
测试第一个
前面的同级::xguielementtypeother
,该子
xguielementtypestatictext
具有属性
名称
文本
变量的值

//XCUIElementTypeCell[preceding-sibling::XCUIElementTypeOther[1][XCUIElementTypeStaticText/@name="' + text + '"]]
例如,使用此输入

<doc>
    <XCUIElementTypeCell>1</XCUIElementTypeCell>
    <XCUIElementTypeCell>2</XCUIElementTypeCell>
    <XCUIElementTypeCell>3</XCUIElementTypeCell>
    <XCUIElementTypeOther>
        <XCUIElementTypeStaticText name="not me"/>
    </XCUIElementTypeOther>
    <XCUIElementTypeCell>4</XCUIElementTypeCell>
    <XCUIElementTypeCell>5</XCUIElementTypeCell>
    <XCUIElementTypeCell>6</XCUIElementTypeCell>
    <XCUIElementTypeCell>7</XCUIElementTypeCell>
    <XCUIElementTypeOther>
        <XCUIElementTypeStaticText name="pick me"/>
    </XCUIElementTypeOther>
    <XCUIElementTypeCell>8</XCUIElementTypeCell>
    <XCUIElementTypeCell>9</XCUIElementTypeCell>
    <XCUIElementTypeCell>10</XCUIElementTypeCell>
    <XCUIElementTypeCell>11</XCUIElementTypeCell>
    <XCUIElementTypeOther>
        <XCUIElementTypeStaticText name="not me"/>
    </XCUIElementTypeOther>
    <XCUIElementTypeCell>12</XCUIElementTypeCell>
    <XCUIElementTypeCell>13</XCUIElementTypeCell>
    <XCUIElementTypeCell>14</XCUIElementTypeCell>
    <XCUIElementTypeCell>15</XCUIElementTypeCell>
</doc>
所选的
xguielementtypecell
元素将是

<XCUIElementTypeCell>8</XCUIElementTypeCell>
<XCUIElementTypeCell>9</XCUIElementTypeCell>
<XCUIElementTypeCell>10</XCUIElementTypeCell>
<XCUIElementTypeCell>11</XCUIElementTypeCell>
8
9
10
11

您应该能够使用一个子
xguielementtypestatictext
测试第一个
前面的兄弟姐妹::xguielementtypeother
,该子
xguielementtypestatictext
具有属性
名称
文本
变量的值

//XCUIElementTypeCell[preceding-sibling::XCUIElementTypeOther[1][XCUIElementTypeStaticText/@name="' + text + '"]]
例如,使用此输入

<doc>
    <XCUIElementTypeCell>1</XCUIElementTypeCell>
    <XCUIElementTypeCell>2</XCUIElementTypeCell>
    <XCUIElementTypeCell>3</XCUIElementTypeCell>
    <XCUIElementTypeOther>
        <XCUIElementTypeStaticText name="not me"/>
    </XCUIElementTypeOther>
    <XCUIElementTypeCell>4</XCUIElementTypeCell>
    <XCUIElementTypeCell>5</XCUIElementTypeCell>
    <XCUIElementTypeCell>6</XCUIElementTypeCell>
    <XCUIElementTypeCell>7</XCUIElementTypeCell>
    <XCUIElementTypeOther>
        <XCUIElementTypeStaticText name="pick me"/>
    </XCUIElementTypeOther>
    <XCUIElementTypeCell>8</XCUIElementTypeCell>
    <XCUIElementTypeCell>9</XCUIElementTypeCell>
    <XCUIElementTypeCell>10</XCUIElementTypeCell>
    <XCUIElementTypeCell>11</XCUIElementTypeCell>
    <XCUIElementTypeOther>
        <XCUIElementTypeStaticText name="not me"/>
    </XCUIElementTypeOther>
    <XCUIElementTypeCell>12</XCUIElementTypeCell>
    <XCUIElementTypeCell>13</XCUIElementTypeCell>
    <XCUIElementTypeCell>14</XCUIElementTypeCell>
    <XCUIElementTypeCell>15</XCUIElementTypeCell>
</doc>
所选的
xguielementtypecell
元素将是

<XCUIElementTypeCell>8</XCUIElementTypeCell>
<XCUIElementTypeCell>9</XCUIElementTypeCell>
<XCUIElementTypeCell>10</XCUIElementTypeCell>
<XCUIElementTypeCell>11</XCUIElementTypeCell>
8
9
10
11

非常感谢大家,伙计们!你们所有的表达都对我有用。我将gtoso的回答标记为解决方案,因为他是第一个回应的人(如果我没弄错的话)。非常感谢大家,伙计们!你们所有的表达都对我有用。我将gtoso的回答标记为解决方案,因为他是第一个回应的人(如果我没弄错的话)。