找不到按钮元素 SELENIUM

Unable to find button element SELENIUM

我有以下按钮代码:

HTML 代码:

<div i="button" class="ui-dialog-button">
<button type="button" i-id="logout-ok">确定</button>
<button type="button" i-id="logout-cancel" class="cancel">取消</button></div>

使用 Xpath 作为检查的代码:

element  = driver.findElement(By.xpath("/html/body/div[7]/div/table/tbody/tr[3]/td/div[2]/button[1]")).click();

我已经尝试使用

 element = 
driver.findElement(By.cssSelector("button.logout-ok")).click();

似乎对我的错误不起作用,请指教。谢谢

请尝试使用 xpath 如下

driver.findElement(By.xpath("//button[@i-id='logout-ok']")).click();

希望对您有所帮助:)