0

I tried to perform click in my html page but it says unable to find the element.

Here is the HTML:

<input type="button" id="btnStopSs" value="Stop" onclick="start_stop_Ss('tag_stopSs');">

Code:

IWebElement user = foxdriver.FindElement(By.Name("user_name"));
IWebElement pwd = foxdriver.FindElement(By.Name("user_passwd"));
user.Clear();
pwd.Clear();
user.SendKeys("admin");
pwd.SendKeys("admin");
IWebElement login = foxdriver.FindElement(By.Name("btnLOGIN"));
login.Click();
Thread.Sleep(3000);
IWebElement stopPage = foxdriver.FindElement(By.TagName("p"));
stopPage.Click();
Thread.Sleep(3000);
IWebElement stoptab = foxdriver.FindElement(By.Id("submenuOnLeftArea0_1"));
stoptab.Click();
Thread.Sleep(3000);
IWebElement stopbtn = foxdriver.FindElement(By.Id("'btnStopSs"));   //=>> Error OpenQA.Selenium.NoSuchElementException: 'Unable to locate element: #btnStopss'
stopbtn.Click();
Thread.Sleep(10000);
IWebElement startbtn = foxdriver.FindElement(By.Id("btnStartSs"));
stoptab.Click();

1 Answers1

0

There seems to be an extra ' character within the Id attribute you have used. Additionally the element seems to be a dynamic element so you need to induce WebDriverWait and you can use either of the following solutions:

  • Id:

    new WebDriverWait(foxdriver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.Id("btnStopSs"))).Click();
    
  • CssSelector:

    new WebDriverWait(foxdriver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input#btnStopSs[value='Stop']"))).Click();
    
  • XPath:

    new WebDriverWait(foxdriver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[@id='btnStopSs' and @value='Stop']"))).Click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352