选择动态元素(POS) - selenium

时间:2018-04-16 08:02:19

标签: c# selenium selenium-webdriver selenium-chromedriver

我在寻找动态变化元素的问题上苦苦挣扎。我们的项目一般是销售点界面,顶部有类别列表,左边是产品列表,右边是篮子。

其中一个类别的

HTLM代码段热门栏目(包含类别):

<div class="nav-button-container" tabindex="-1" style="width: 100%; display: inline-block;"><button class="nav-button nav-button-inactive" style="color: rgb(243, 235, 230); background-color: rgb(0, 0, 0);">Kotzonet</button></div>
<button class="nav-button nav-button-inactive" style="color: rgb(243, 235, 230); background-color: rgb(0, 0, 0);">Kotzonet</button>

xPath

//*[@id="root"]/div/div/div/div[2]/div[1]/div/div/div/div/div[3]/div/div/button

班级正在根据选择进行更改,如果选择了特定类别,则结尾有&#34;活动&#34;标签,其他类别有&#34;不活跃&#34;。在我看来,类别的值(文本输入)可能很重要,以便以某种方式找到它。打开POS后,它指向&#34;收藏夹&#39;类别(表示其他类别无效)。

你可以给我任何建议吗?

1 个答案:

答案 0 :(得分:0)

根据您共享的 HTML 点击按钮,文字为 Kotzonet ,您可以使用以下代码行:

driver.FindElement(By.XPath("//button[@class='nav-button nav-button-inactive' and contains(.,'Kotzonet')]")).Click();
相关问题