简体   繁体   中英

How to click button using selenium c#

<button class="btn btn-outline-primary btn-lg" id="btnPermission">GO</button>

The above codes are from a website, however I am unable to click this button despite trying multiple attempts. What should I do?

 IWebElement reklamgec3 = driver.FindElement(By.CssSelector("#btnPermission"));
 ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", reklamgec3);



IWebElement reklamgec3 = driver.FindElement(By.ClassName("btn-outline-primary"));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", reklamgec3)


IWebElement reklamgec3 = driver.FindElement(By.XPath("//*[@id="btnPermission"]"));
   ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", reklamgec3)


 IWebElement reklamgec3 = driver.FindElement(By.Id("btnPermission"));
  ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", reklamgec3)

      IWebElement reklamgec3 = driver.FindElement(By.CssSelector("#btnPermission"));
        reklamgec3.Click();

How to click button using c# selenium. The above does not work for me.

You need to use an explicit wait :

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));

wait.Until(d => d.FindElement(By.Id("btnPermission")).Click());

Waiting for the existence of a element is frequently not enough. You need to wait for it to be clickable. Many times that just means attempting to find then click the element until the click event succeeds.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM