![](/img/trans.png)
[英]NoSuchElementException: no such element: Unable to locate element during web scrape
[英]Unable to find Element on Web page during Automation
我正在使用Selenium Web驅動程序(2.44)自動化某些網頁,自動化運行期間瀏覽器出現意外錯誤。 請看下圖:
因此,發生這種情況時,我的頁面將掛起,並且框架無法找到當前網頁中的任何元素。 我試圖升級/降級IE驅動程序。
當我雙擊此錯誤符號時,出現以下彈出IE窗口:
打開瀏覽器的保護模式。 在選項的“安全性”選項卡中。 如果這不起作用,請確保每個區域都使用相同的選項(打開或關閉)。 有四個區域(Intranet,Trusted,Internet和Restricted)。
這是一些可以為您(IE)完成的代碼:
// Intranet
private const string REG_KEY_IE_ZONE_1 = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1";
// Trusted
private const string REG_KEY_IE_ZONE_2 = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2";
// Internet
private const string REG_KEY_IE_ZONE_3 = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3";
// Restricted
private const string REG_KEY_IE_ZONE_4 = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\4";
public static void SetIESecurityToProtected()
{
// 3 is off, 0 is on
try
{
// Intranet
if ((int)Registry.GetValue(REG_KEY_IE_ZONE_1, "2500", -1) == 3)
{
Registry.SetValue(REG_KEY_IE_ZONE_1, "2500", 0);
}
// Trusted
if ((int)Registry.GetValue(REG_KEY_IE_ZONE_2, "2500", -1) == 3)
{
Registry.SetValue(REG_KEY_IE_ZONE_2, "2500", 0);
}
// Internet
if ((int)Registry.GetValue(REG_KEY_IE_ZONE_3, "2500", -1) == 3)
{
Registry.SetValue(REG_KEY_IE_ZONE_3, "2500", 0);
}
// Restricted
if ((int)Registry.GetValue(REG_KEY_IE_ZONE_4, "2500", -1) == 3)
{
Registry.SetValue(REG_KEY_IE_ZONE_4, "2500", 0);
}
}
catch (Exception e)
{
// handle your exception or record it...
}
}
這將修改注冊表...所以...通讀代碼,並確保您了解它的作用。 這個對我有用。 我看到不同的人有不同的行為,但這就是我要做的。
這是官方要求披露:
還有其他一些注意事項,例如需要考慮瀏覽器窗口焦點,因此建議您仔細閱讀驅動程序文檔: https : //code.google.com/p/selenium/wiki/InternetExplorerDriver
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.