VBA IE Automation: Get URL from within element - html

I am trying to get the URL from inside the second element in the "pShowMore" class.
I have this:
For Each wd In CreateObject("Shell.Application").Windows
If InStr(wd.LocationName, "Institution") <> 0 Then
Exit For
End If
Next wd
Dim newURL As String
newURL = wd.document.getElementsByClassName("pShowMore").getElementsByTagName("a")(1).getAttribute("href")
And I get the error: 438-"Object doesn't support the property or method" for the retrieval (i.e., wd.document.....)
What can I do to get the URL in the href?
Also, why does it not support the property or method?

It turns out I was just getting an error cycling through the open windows.
I used
On Error Resume Next
This solved the specific problem I was having.

Related

Wait until an HTML5 video loads-Typescript

I have a video tag, that I dynamically change its source as I am letting the user to choose from a number of videos from the database. The problem is that, i am getting error while calling the load function
Here is my code:
var video = <HTMLInputElement>document.getElementById('introVideo');
video.src = this.videoUrl;
video.load();`
But doing so i am getting a warning
[ts] Property load does not exists on type HTMLInputElement
I did not test this, but try casting your HTML element to a HTMLVideoElement instead of HTMLInputElement because the method .load() does not exist on HTMLInputElement type.
Cheers.

CefSharp and frames, only retrieving HTML from first frame

pcpao.org/general.php?strap=152814186280001650
In trying to get the full HTML from that site, .GetSourceAsync and .ViewSource, both only show the 'frameset' HTML. Using the ShowDevTools option, the full HTML data is in both the elements collection and the Sources of the Chrome-devtools.
I am running this after the webpage has loaded, but it should all be there still since its in the dev-tools?
What am I missing to get the full HTML out of a navigated site. I suspect this has to do with frames but after an hour of googling and reading old messages I see this only tangentially mentioned.
Winforms
package id="cef.redist.x64" version="3.2526.1362" targetFramework="net46"
package id="cef.redist.x86" version="3.2526.1362" targetFramework="net46"
package id="CefSharp.Common" version="47.0.3" targetFramework="net46"
package id="CefSharp.WinForms" version="47.0.3" targetFramework="net46"
I was having the same issue trying to get click on and item located in a frame and not on the main frame. Using the example in your answer, I wrote the following extension method:
public static IFrame GetFrame(this ChromiumWebBrowser browser, string FrameName)
{
IFrame frame = null;
var identifiers = browser.GetBrowser().GetFrameIdentifiers();
foreach (var i in identifiers)
{
frame = browser.GetBrowser().GetFrame(i);
if (frame.Name == FrameName)
return frame;
}
return null;
}
If you have a "using" on your form for the module that contains this method you can do something like:
var frame = browser.GetFrame("nameofframe");
if (frame != null)
frame.EvaluateScriptAsync("document.getElementById('whateveridyouwanttoclick').click();");
Of course you need to make sure the page load is complete before using this, but I plan to use it a lot. Hope it helps!
Thanks, some examples from previous versions had me confused how this works. I was looking for something like this.
var frameIdent = Browser.GetBrowser().GetFrameIdentifiers();
var result = Browser.GetBrowser().GetFrame(frameIdent.Last()).GetSourceAsync().Result;
textBox1.Text = result.ToString();
So I guess the way to get all HTML from a site is loop through the frames identifiers list, get the result from each frame via GetSourceAsync and concatenate them all to a string.

ReportViewer showing broken images in Chrome

I'm using ReportViewer 10.0. In Google Chrome, the lines come with a broken image called blank.gif. But IE and Firefox are working fine.
Here's an example with the images circled:
Any ideas on how to fix this?
Just add the following CSS from SQL Reporting Services - Viewer broken in Non-IE Browsers:
body:nth-of-type(1) img[src*="Blank.gif"]{
display:none;
}
The current solution will mask the issue, but won't address the underlying problem, which is that when browsers besides IE are composing the request for the gif (which SSRS just uses to replace padding), they don't know to include the IterationId query string parameter.
As SQL Reporting Services Viewer broken in Non-IE Browsers points out, if you're using the ReportViewer, you can fix this in your application routing under Application_BeginRequest like this:
protected void Application_BeginRequest(object sender, EventArgs e)
{
// Original fix credit to Stefan Mohr
// Bug fix for MS SSRS Blank.gif 500 server error missing parameter IterationId
// https://connect.microsoft.com/VisualStudio/feedback/details/556989/
HttpRequest req = HttpContext.Current.Request;
if (req.Url.PathAndQuery.StartsWith("/Reserved.ReportViewerWebControl.axd") &&
!req.Url.ToString().ToLower().Contains("iteration") &&
!String.IsNullOrEmpty(req.QueryString["ResourceStreamID"]) &&
req.QueryString["ResourceStreamID"].ToLower().Equals("blank.gif"))
{
Context.RewritePath(String.Concat(req.Url.PathAndQuery, "&IterationId=0"));
}
}
Workaround: use rectangles/textboxes/tablix cells and only have one of their borders showing. Works on chrome. For the OP, he can add extra columns as spacers between the data columns and skip showing the border for those.
I had the same error with Reportviewer version 10 so I update to version 14, it solve the problem and get some enhancements, compelte guide here
In my case its response not working in test mode (Localhost), but I corrected and now it works , instead of putting " StartsWith " I put "Contains". It's the code:
Protected Sub Application_BeginRequest(sender As Object, e As EventArgs)
' Original fix credit to Stefan Mohr
' Bug fix for MS SSRS Blank.gif 500 server error missing parameter IterationId
' https://connect.microsoft.com/VisualStudio/feedback/details/556989/
Dim req As HttpRequest = HttpContext.Current.Request
If req.Url.PathAndQuery.Contains("/Reserved.ReportViewerWebControl.axd") AndAlso Not req.Url.ToString().ToLower().Contains("iteration") AndAlso Not [String].IsNullOrEmpty(req.QueryString("ResourceStreamID")) AndAlso req.QueryString("ResourceStreamID").ToLower().Equals("blank.gif") Then
Context.RewritePath([String].Concat(req.Url.PathAndQuery, "&IterationId=0"))
End If
End Sub
Hope you help,
As the other answers, I solved this problem adding the following code to my Global.asax file:
void Application_BeginRequest(object sender, EventArgs e)
{
//The following code is a hack for stopping a broken image from magically appearing on SSRS reports in chrome
//where ever a line is used in the report.
Uri u = HttpContext.Current.Request.Url;
//If the request is from a Chrome browser
//AND a report is being generated
//AND there is no QSP entry named "IterationId"
if (HttpContext.Current.Request.Browser.Browser.ToLower().Contains("chrome") &&
u.AbsolutePath.ToLower().Contains("reserved.reportviewerwebcontrol.axd") &&
!u.Query.ToLower().Contains("iterationid"))
HttpContext.Current.RewritePath(u.PathAndQuery + "&IterationId=0");
}
But, maybe you had missed or don't have the Global.asax file, as happened to me. So select your solution and go to:
File > New > File > Web > C#/VB.Net > Global Application Class
Save it as Global.asax, paste the code and it will solve your problem.

document.getElementById(control).value not working with IE8

var tagID = document.getElementByn("<%=ddlSectionHeaderID%>").value;
var tagIndex = document.getElementById("<%=ddlSectionHeaderID%>").selectedIndex;
var tagName = document.getElementById("<%=ddlSectionHeaderID%>").children(tagIndex).innerText;
var exportID = document.getElementById("<%=hdnExportID%>").value;
This gives me "Object doesn't support this property"
It would help to see the rendered output and what references resulted in the rendered script.
The "Object doesn't support this property" error means that you are trying to access a property that does not exist for that object. perhaps when this script is rendered, what you think should be a select element is actually a text input. If that is the case, the selectedIndex property wont exist (this is just one possibility - you will know more if you were able to see the resulting string).

Implement anchor onclick event using HTML document object from Excel VBA

I am trying to implement an onclick event for an anchor tag on a website from Excel VBA. The following code gives me error message.
Set iePage = ieApp.document
Set ieAnchor = iePage.getElementsByTagName("A").Item(5)
ieAnchor.onclick = true
The error message is a run time error that says Not Implemented
Can someone please advise on getting this event to fire?
BTW, I've used the basic iePage.Links(1).click event without a problem...
but I need to execute a javascript function called from the anchor onclick event.
If I understand your question correctly, you are trying to respond in VBA to the user clicking an anchor? If so you need to create an EventHandler for OnClick event. To do this you must restructure your code to meet the following criteria:
You must declare said Anchor variable using the "WithEvents" keyword in order to respond to events.
To use the "WithEvents" keyword you must declare your Anchor variable at the module level.
You must also be inside a Class module to use the WithEvents keyword.
Finally you need to create the Event Handler itself via the drop down menus in the top of the VBE or just paste in the code below. How to use the code:
Create a Class Module named "MyClass" and paste in the following:
Option Explicit
Private WithEvents ieAnchor As MSHTML.HTMLAnchorElement
Public Sub Main()
Dim iePage As MSHTML.HTMLDocument
Set iePage = ieApp.document
Set ieAnchor = iePage.getElementsByTagName("A").Item(5)
End Sub
Private Function mobjMyAnchor_onclick() As Boolean
''//Your Code Here
End Function
To use the code in the class you can then add a standard module and call the code like this:
Public Sub Example()
Dim objMyClassVariable As MyClass
Set objMyClassVariable = New MyClass
objMyClassVariable.Main
End Sub
Edit:
To call a JavaScript function you can just use the JavaScript URL scheme with the InternetExplorer.Navigate method. Ex: ie.Navigate "JavaScript:SomeFunc()". Or you can actually just cause the click to occur using the HTMLAnchorElement.Click method: ieAnchor.Click.