簡體   English   中英

xpath可用於硒記錄,但不能在Eclipse中運行

[英]xpath works in selenium recording, but does not run in Eclipse

我試圖在以前在Selenium中記錄的Eclipse中運行測試。 我能夠通過使用XPath使其在Selenium中運行。 但是,在Eclipse中,我收到了NoSuchElement錯誤。 我試圖單擊頁面上的一個選項卡,問題是這些選項卡未作為按鈕列出,但實際上在表中。 這是我現在已有的行。

driver.findElement(By.xpath("(//div[@onclick=\"parent.frames.contentFrame.location='/messaging/maintfList.jsp?clearUIPath=true&uiPathLabel=Forms'\"])")).click();

這是檢查元素時顯示的內容。 所有選項卡均列為正常菜單,唯一的區別是路徑標簽。

div class="menu-normal" onclick="parent.frames.contentFrame.location='/messaging/maintfList.jsp?clearUIPath=true&uiPathLabel=Forms'"

我會嘗試

driver.findElement(By.cssSelector("div[onclick='parent.frames.contentFrame.location='/messaging/maintfList.jsp?clearUIPath=true&uiPathLabel=Forms']")).click();

在Java中轉義任何需要它的東西。

xpath是一種發現事物的非常低效的方法,幾乎​​總是有一種更好的方法。 在這種情況下,CssSelector可以找到您想要的東西。

編輯:我看過Java文檔,請嘗試使用此行

driver.findElement(By.cssSelector("div[onclick=\"parent.frames.contentFrame.location='/messaging/maintfList.jsp?clearUIPath=true&uiPathLabel=Forms'\"]")).click();

您也可以嘗試以下方法:

driver.findElement(By.xpath("//div[@class='menu-normal'][2]")).click();

//這里[2]是頁面上正常菜單的位置號。 讓我們假設有4個選項卡具有相同的類,並且您想單擊第二個選項卡,則可以使用上面的代碼。

如果沒有幫助,請分享您的HTML代碼。

暫無
暫無

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

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