我想使用 selenium webdriver 代码单击下拉按钮。 HTML如下:
<div class="btn-group bootstrap-select show-tick ua-bo-select" style="width: 222px;">
<button class="btn dropdown-toggle bs-placeholder btn-default" role="button" data-toggle="dropdown" type="button" data-id="invContactList" title="" data-original-title="Nothing selected">
准确的代码是什么?
请检查我的应用程序正在使用的下拉按钮
最佳答案
此 HTML 中没有“a”标签。所以使用 Select 将不起作用。相反,这样做:
driver.findElement(By.xpath(".//button[@data-toggle='dropdown']")).Click();
然后监视下拉值并提供另一个 xpath 或 ID。它会起作用的。
我认为您给出的 xpath 是错误的。请尝试上面或下面的操作:
driver.findElement(By.xpath(".//button[@data-id='invContactList']")).Click();
关于java - 想要使用 selenium webdriver 代码单击下拉按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42974107/