Selenium无法从asp页面获得任何标签,如“表”或“a”。我也尝试过让“体”标签,在这种情况下,它承认,但如下抛出异常:为什么Selenium网络驱动程序无法从aspx网页获取'标签'?
> Unhandled Exception: OpenQA.Selenium.StaleElementReferenceException:
> Element bel ongs to a different frame than the current one - switch to
> its containing frame to use it at
> OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response
> erro rResponse) at
> OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String
> driverCommandToExecu te, Dictionary`2 parameters) at
> OpenQA.Selenium.Remote.RemoteWebElement.GetAttribute(String
> attributeName)
我用C#代码:
FirefoxProfile firefoxProfile = new FirefoxProfile(@"C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\rwyq8vbx.default");
IWebDriver driver = new FirefoxDriver(new FirefoxBinary(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"), firefoxProfile);
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl(@"http://epmweb.apac.bbc.com/pwa/_layouts/pwa/mytssummary.aspx");
System.Threading.Thread.Sleep(10000);
driver.SwitchTo().DefaultContent();
List<IWebElement> frameset = driver.FindElements(By.TagName("iframe")).ToList();
Console.WriteLine(frameset.Count);
foreach (var v in frameset)
{
Console.WriteLine("fName : " + v.GetAttribute("name"));
}
IWebElement[] rows = driver.FindElements(By.TagName("body")).ToArray();
Console.WriteLine(rows.Length);
foreach (var v in rows)
{
Console.WriteLine("Name : "+v.GetAttribute("id"));
}
框架指望它给零和行的长度1.
显然,当我点击查看页面源&保存该页面为html。我能够获得标签。
任何帮助,我在这里错过了什么?
编辑::我试着得到网页什么硒得到作为网页。它返回:`
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html
> xmlns="http://www.w3.org/1999/xhtml"><head><title>My Timesheets -
> Project Web Access</title><link
> href="chrome://ietab2/skin/ietab-favicon-iedoc.png" rel="icon" />
> </head> <body onload="window.setTimeout(function() { init(); },0);"
> style="margin:0; padding:0;overflow:hidden">
>
> <script type="text/javascript"> var gIETab = null;
>
> function init(){
> gIETab = document.getElementById("IETab2");
> try {
> // This is needed to avoid an "Activate Plugin" prompt in Fx 27+.
> // It's not documented, thus the try/catch for back-compat
> gIETab.QueryInterface(Components.interfaces.nsIObjectLoadingContent).playPlugin();
> } catch(ex) {
> }
>
> if(!gIETab || !gIETab.navigate)
> { // Wait for it to show up
> window.setTimeout(function() { init(); }, 200); return; }
>
> var m=/(\?url=)(\S+)$/.exec(document.location.href);
> if(m)
> {
> var url = decodeURI(m[2]);
> if ((url.indexOf("about:") == 0) || (url.indexOf("chrome://") == 0))
> url = 'http://www.ietab.net/ie-tab-v2-documentation?from=' + url;
> gIETab.navigate(url);
> } }
>
> var IETabCalls = { goBack: function() { gIETab.goBack(); },
>
> goForward: function() { gIETab.goForward(); },
>
> navigate: function(url) { gIETab.navigate(url); },
>
> refresh: function() { gIETab.refresh(); },
>
> stop: function() { gIETab.stop(); },
>
> saveAs: function() { gIETab.saveAs(); },
>
> print: function() { gIETab.print(); },
>
> printSetup: function() { gIETab.printSetup(); },
>
> printPreview: function() { gIETab.printPreview(); },
>
> viewSource: function() { gIETab.viewSource(); },
>
> find: function() { gIETab.find(); },
>
> cut: function() { gIETab.cut(); },
>
> copy: function() { gIETab.copy(); },
>
> paste: function() { gIETab.paste(); },
>
> selectAll: function() { gIETab.selectAll(); },
>
> focus: function() { if (!gIETab) { // It might not have loaded
> yet, wait for the control to fully initialize
> window.setTimeout(function() { IETabCalls.focus(); }, 100); }
> else { gIETab.focus(); } } }
>
> window.onpageshow = function(e) { if (e.persisted)
> window.setTimeout(function() { init(); }, 0); }
>
> function createIETab() {
> var obj = document.createElement("object");
> obj.id = "IETab2";
> obj.style.width = "100%";
> obj.style.height = "100%";
> // Waterfox/x64 example:
> // Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:16.0) Gecko/20121026 Firefox/16.0
> // Firefox/x32 on Win64:
> // Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Firefox/17.0
> // Firefox/x32 on Win32
> // Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20100101 Firefox/16.0
> //
> if (window.navigator.userAgent.indexOf("Win64; x64;") != -1)
> obj.setAttribute("type", "application/ietab2_x64");
> else
> obj.setAttribute("type", "application/ietab2");
> document.body.appendChild(obj); } // Navigation happens later, but create the IE Tab object immediately createIETab(); </script><object
> id="IETab2" style="width: 100%; height: 100%;"
> type="application/ietab2"></object>
>
>
> </body></html>
`
但是,当我手动检查网页的源文件,它看起来正常,因为它应该是。
它不一定是**“iframe”标签**。它也可以是一个**框架**标签。您是否注意到了这种可能性? – Subh 2015-02-11 17:47:34
也没有“框架”标签。只有在网站上运行时才能获取标签。如果我检查页面源并将其保存在本地HTML页面中,我可以获取标签。此外,它可以在网站上运行时获取身份标记,但不能识别其身份或文本。它实际上是一个内部网站。这没关系,对吧?我猜想启用了一些安全性当我使用chrome打开相同的链接时,会出现错误,“至少使用Internet Explorer版本6才能使用Project Web Access”。 – mkkhedawat 2015-02-12 05:01:22