我試圖單擊使用id的按鈕,然後使用class名稱,然後xpath,id會動態給出。你能告訴我確切的XPath此代碼使用xpath在黃瓜中單擊按鈕
package step_definitions;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class sharedshelf {
public WebDriver driver;
public sharedshelf()
{
driver = Hooks.driver;
}
@When("^I press option button$")
public void i_press_option_buttion() throws Throwable {
// Write code here that turns the phrase above into concrete actions
Thread.sleep(5000);
driver.findElement(By.xpath("//button[text()='Edit']")).click();
}
的Html
<button type="button" id="ext-gen494" class=" x-btn-text" tabindex="4">Edit</button>
你有什麼錯誤? – Guy
您的xpath看起來正確。那有什麼問題?有什麼異常嗎? –
org.openqa.selenium.InvalidElementStateException:無效的元素狀態 它顯示這個 – ali