-1

how to find element for this below html tag ?

I am getting

exception: no such element: Unable to locate element:

{"method":"xpath","selector":"//*[@id='divMain']/div/app-train-list/div[2]/app-modify-search/p-confirmdialog/div/div/div[3]/html/body/app-root/app-home/div[3]/div/app-train-list/div[2]/app-modify-search/p-confirmdialog/div/div/div[3]/button"}

IWebElement berthOK = driver.FindElement(By.XPath("//*[@id='divMain']/div/app-train-list/div[2]/app-modify-search/p-confirmdialog/div/div/div[3]/html/body/app-root/app-home/div[3]/div/app-train-list/div[2]/app-modify-search/p-confirmdialog/div/div/div[3]/button"));
if (berthOK.Displayed)  //*[@id='divMain']/div/app-train-list/div[2]/app-modify-search/p-confirmdialog/div/div/div[3]
berthOK.Click();
cruisepandey
  • 28,520
  • 6
  • 20
  • 38

1 Answers1

0

I guess it's OK button that you wanna click.

IWebElement berthOK = driver.FindElement(By.XPath("//span[text()='OK']/.."));
if(berthOK.Displayed)
berthOK.Click();

or for more reliability make sure to use WebDriverWait :

new WebDriverWait(driver, TimeSpan.FromSeconds(3)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//span[text()='OK']/.."))).Click();
cruisepandey
  • 28,520
  • 6
  • 20
  • 38