我正在用Selenium Chrome WebDriver最新版本構建一個小型自動測試腳本,但是現在我面臨一個問題,即使在切換到iFrame時也嘗試獲取WebElement。Selenium - 在iFrame中獲取WebElement時出錯
這是HTML的構建方式:
你可以檢查一下,還有另外一個頁面「鑲嵌」裏面的iFrame,並且按鈕的定義如下(這是我選擇的一部分):
這是我使用來獲取WebElement的方式(顯然不及格):
WebElement frameAperturar =
driver.findElement(By.xpath("//iframe[@title='Aperturar']"));
driver.switchTo().frame(frameAperturar);
asociarSiniestroButton = driver.findElement(By.xpath("//button[@aria-label='Asociar Siniestro']"));
asociarSiniestroButton.click();
這是我當我試圖讓WebElement異常:
no such element: Unable to locate element: {"method":"xpath","selector":"//button[@aria-label='Asociar Siniestro']"}
(會話信息:鉻= 60.0.3112.113)
你知道我怎麼能得到的元素在切換到框架後,iFrame內的頁面?
什麼是你得到 – SaiPawan
這個錯誤是我得到了異常:「沒有這樣的元素:找不到元素:{」方法「:」的XPath「」 (會話信息:chrome = 60.0.3112.113) (驅動程序信息:chromedriver = 2.32.498550(9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform = Windows NT 6.1(選擇器「:」//按鈕[@ aria-label ='Asociar Siniestro']「} (警告:服務器沒有提供任何堆棧跟蹤信息)「 –
已更新my anwer –