如何为class
调用 xpath?
<button class="inline" data-ember-action="" data-ember-action-11310="11310">Load</button>
我试图通过以下方式调用它:
By.xpath("//span/button[text()='Load'][1]");
但它无法定位元素。
使用以下 xpath:
//button[@class='inline' and text()='Load']
该元素似乎是启用 Ember.js 的元素,因此要click()
该元素,您必须诱导 WebDriverWait for the elementToBeClickable,您可以使用以下任一解决方案:
-
cssSelector
:new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.inline[data-ember-action]"))).click();
-
xpath
:new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='inline' and text()='Load'][@data-ember-action]"))).click();