簡體   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

我正在嘗試使用其 ID 作為定位器來獲取按鈕元素。 我有多個頁面,所有頁面上都存在相同的按鈕。使用下面提到的相同代碼,我能夠在其中 2 個頁面上獲取元素,但在其他頁面上,它返回的異常為

“沒有這樣的元素:無法定位元素:{"method":"css selector","selector":"#btn-show-support-info"}(會話信息:chrome=80.0.3987.132)”

代碼行:

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

完整的 XPATH:

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

我也嘗試過使用 xpath,但沒有運氣。

任何幫助將不勝感激。 :)

檢查它是否在所有頁面的路徑下。 如果按鈕在框架內,則需要先切換到框架,然后再查找元素

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM