简体   繁体   中英

Unable to locate element in Selenium using ID. Able to get the element on one page. However unable to locate when I navigate on another page

I am trying to get a button element using its ID as locator. I have multiple pages and same button is present on all the pages.Using the same code as mentioned below, I am able to get the element on 2 of the pages but on other pages, its returning with exception as

"no such element: Unable to locate element: {"method":"css selector","selector":"#btn-show-support-info"} (Session info: chrome=80.0.3987.132)"

Code line:

_btnSupportInfo = new WebDriverWait(
    _Driver, 
    TimeSpan.FromSeconds(Convert.ToInt32(Environment.GetEnvironmentVariable("waitTime"))))
    .Until(ExpectedConditions.ElementToBeClickable(By.Id("btn-show-support-info"))
);

Complete XPATH:

/html/body/app-root/main/project-shell/div/div/client-header/div/form/div[6]/support-info/button

I have tried using xpath as well but no luck.

Any help would be greatly appreciated. :)

Check whether it's under the path in all the pages. If the button is inside frame then you need to switch to the frame first and then to look for the element

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