简体   繁体   English

无法使用 ID 在 Selenium 中定位元素。 能够在一页上获取元素。 但是当我在另一个页面上导航时无法定位

[英]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.我正在尝试使用其 ID 作为定位器来获取按钮元素。 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我有多个页面,所有页面上都存在相同的按钮。使用下面提到的相同代码,我能够在其中 2 个页面上获取元素,但在其他页面上,它返回的异常为

"no such element: Unable to locate element: {"method":"css selector","selector":"#btn-show-support-info"} (Session info: chrome=80.0.3987.132)" “没有这样的元素:无法定位元素:{"method":"css selector","selector":"#btn-show-support-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:完整的 XPATH:

/html/body/app-root/main/project-shell/div/div/client-header/div/form/div[6]/support-info/button /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.我也尝试过使用 xpath,但没有运气。

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如果按钮在框架内,则需要先切换到框架,然后再查找元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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