[英]TypeError: Cannot read property “removeAttribute” of null
[英]JavascriptExecutor: Cannot read property 'removeAttribute' of null
我正在使用Javascript executor刪除readonly
屬性,但它給出了錯誤。 Cannot read property 'removeAttribute' of null
。
我看到過很多不同的帖子,人們證實從Chrome刪除AdBlock后可以正常工作。 我不知道什么是AdBlock,以及如何在運行時從Chrome Binary中將其刪除,因此我嘗試使用Firefox(Gecko驅動程序),但它也會引發相同的錯誤。
碼:
driver.get("http://jsfiddle.net/343Rb/");
runJS().executeScript("document.getElementById('myInput').removeAttribute('readonly')");
我嘗試過的瀏覽器:Windows 7上最新的Chrome Binary,Firefox(最新的GeckoDriver)
我經過的鏈接:
上面的幾篇文章完全基於JS,所以我相信這是他們沒有回復我的原因。
我正在使用Selenium 3.0,Windows 7,Firefox,Chrome,Java,Testng
問題是您想要的元素在<iframe>
內部。 您需要在查詢元素之前切換到它:
driver.switchTo().frame('result');
要么:
driver.switchTo().frame(driver.findElement(By.name('result')));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.