按钮元素未被点击

时间:2015-07-03 07:44:48

标签: c# selenium selenium-webdriver

按钮的HTML

<button id="exist_user" onclick="ExtUpdtPnl();" type="button" style="background-color: rgb(187, 187, 187);">
<i class="fa fa-gear fa-fw"></i>
Update Existing User
</button>

我使用了以下多种方法

driver.FindElement(By.Id("exist_user")).Click(); 
driver.FindElement(By.XPath("/html/body/form/div[4]/div/div/div[2]/button[1]"));

请帮助..

2 个答案:

答案 0 :(得分:0)

请尝试driver.FindElement(By.Id("exist_user")).InvokeMember("click");

答案 1 :(得分:0)

尝试使用JavascriptExecutor:

WebElement element = driver.findElement(By.xpath(".//button[@id='exist_user']"));

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("document.getElementById('exist_user').click();");