I am using Visual Studio 2010 and coding in VB.
I have a form with a WebBrowser object in it.
I have control over the HTML on the pages.
I need the user to be able to select a portion of text in the WebBrowser object and save it.
In the save process, I need to capture the selected text, the ID of the HTML element that contains the selected text, and the URL. Then when the user goes back to that page, the program can place an icon on the page right next to that object.
I do not have any code to accomplish this yet, I do not have much experience with the WebBrowser object so I didn't even know where to start. I can however give the names of my form objects and inform you that all of the html elements have an ID.
Form : frmContent
WebBrowser : wbContent
I am guessing that I could even record coordinates of the selected portion of text instead of the html element. Either way, the final outcome needs to save a list of these locations paired with their url so that for every saved "bookmark", there will be an icon placed on the page of that url in the saved location of the page.
Found that this works rather well for me.
GetElementFromPoint(e.ClientMousePosition)
I was able to set this to a variable and then able to get the attributes from the element.
Dim bookmarkElement = wbContent.Document.GetElementFromPoint(e.ClientMousePosition)
Dim elementID = bookmarkElement.GetAttribute("id").ToString()
Problem solved.
Related
On my Webpage I have three Dropdown Controls. When First Option is selected in the First Combo, the Second Combo Control Gets Populated and similarly on selecting an Option in the Second Combo populates the Third Combo Control.
Each Combo Control has a above it. Using Selenium in VB.net, I am able to find the First Combo Control and iterate through each Option Available. The Challenge I am facing is that, the label on Second and third Combo gets its text from the the Selected Option of the First and Second Combos, respectively. However, the XPath changes randomly with each option selected due to which the FindElement(By.Xpath) fails.
The example Combos are available this Link Set of Three Combos
I tried using the following VB.net Code
Dim CWEstring = "./following-sibling::select"
GE = New SelectElement(driver.FindElement(By.XPath(CWEstring)))
and
Dim GEString = "./following-sibling::select"
GE = New SelectElement(driver.FindElement(By.XPath(GEString )))
I did my research for few days but couldn't get the answer, so posting here for help.
Use the following xpath to identify the element.
1st dropdwon:
//select[#id='edit-field-select-zone2-value']
2nd Dropdown:
//select[#id='edit-field-cce-army-no-1dinjan-cwe-tid']
3rd dropdown:
//select[#id='edit-field-pm-khonsa-tid']
Please note you have to provide some wait after selecting each dropdown item to appear next dropdown on the webpage.
I Downloaded the webpage Source and Edited the code to bear minimum HTML content so that all three Combo Controls are visible and save the html content as a .htm file on local disk.
Using chrome I opened the .htm file. Then Using MS-Excel From Web under Data tab Scraped the data from the local .htm file.
Now I had all values under one Column Header name. I converted all values under column name into an array.
Using VB.net and Selenium technology, I iterated through each combo control and saved the data to a New Excel File.
More Challenges came to fore. Therefore, I used Try...Catch method to trap the error and Continue the Iterations (Loops).
And now I have all the values the way I wanted them.
I´m creating a form that displays the info of all of the employees, including their photo.
When in design view, I've tried using an image control and defining in its control source.
However, when I change to form view and navigate the employees records, their photo isn´t shown.
I've tried changing the field (where the photos are stored) data type to text, instead of hyperlink (as shown in this youtube video: https://www.youtube.com/watch?v=f5ZOOMrDjtU ) but the photos still do not appear.
The photos are stored as hyperlinks, that show the file path, and if i'm in datasheet view of the table, I can click on the employees photo hyperlink and it opens their photo.
Also, in access options, I have this picture property storage format selected: and the images are jpg files.
Does someone know how I can solve this issue? What could I have done wrong?
Thank you.
A true hyperlink in Access is made of 3 parts separated by # character.
display text # file name # any reference within the file
More info http://allenbrowne.com/casu-09.html
The hyperlink structure won't work in Image control ControlSource property and can't simply convert the hyperlink field to a text type as the resulting string will not be a valid file path. Either manually enter correct image file path or use string manipulation code to extract file path part from the hyperlink field and save to a text field (x represents fieldname):
Mid(Left(x,InStrRev(x,"#")-1),Instr(x,"#")+1)
On second thought, that expression could be in the ControlSource property so the hyperlink field could be retained as is and a text field not needed.
More info on expressions in ControlSource property: Access Form: `abc.Picture="xyz.jpg"` makes listbox & textboxes "blink" once
Private Sub document_PrintPage(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
Handles docToPrint.PrintPage
' Insert code to render the page here.
' This code will be called when the control is drawn.
' The following code will render a simple
' message on the printed document.
'Dim text As String = "In document_PrintPage method."
'Dim printFont As New System.Drawing.Font _
' ("Arial", 35, System.Drawing.FontStyle.Regular)
'' Draw the content.
'e.Graphics.DrawString(text, printFont, _
' System.Drawing.Brushes.Black, 10, 10)
End Sub
I have code to display a printer dialog box that will call this procedure to render a document for printing. The document I want to print is accessible from a URL as an HTML webpage, and the webpage is understood to be available for printing. The sample code above, for rendering strings only, will not do what I need. I was thinking of using system.drawing.graphics.drawimage, if that can be made to work. Any ideas? I'm having trouble fully picturing the process of converting the HTML page to an image datatype. If that's not necessary, all the better.
Is there any reason you can't use System.Windows.Forms.WebBrowser?
It has a Print() method, which would seem to make your task easier. . . 8-)
Rendering HTML into an image for printing is not a trivial task. One way or the other you'll need to leverage a library that knows how to do it.
First I changed my printer dialog call so that it runs client side by using a javascript function. That was easy. The next thing was to isolate the area to be printed to the rectangle enclosing the satellite map loaded as source into an iframe. As my understanding is the javascript printer dialog would dump the whole page to the printer, I tried several things and eventually enclosed the iframe in its own div section on the asp panel that has the html button tag that calls the printer dialog and the iframe. This was enough to get only the map printed. One thing that may be necessary to allow this is that you need to use subdomains to trick the browser into thinking the iframe host and the document host are on the same domain-- I had already worked with the mapping company and our local hosting company to get that part done. The only thing left to do is to get the iframe to hold a selected zoom status of the map when I click to open the printer dialog. I will post another question for opinions on how to get an asp panel to freeze its view, or whatever other trick might enable that.
I'm using the .Net 4.0 WebBrowser (from System.Windows.Controls). In my application the user can modify the html data and the webbrowser shows an update. The application should then automatically scroll to the previous element that was displayed.
I'm using WPF / c# 4.0 on windows 7.
In detail:
In the code I call WebBrowser.NavigateToString(htmlData1);
the user scrolls to an arbitrary position
the user changes (somehow) the html document
now I would like to find (and remember) the first html element that is displayed
I call WebBrowser.NavigateToString(htmlData2);
now I would like to use the memorized element to automatically scroll the html document (I know that there is IHTMLElement.scrollIntoView() to do this)
So the question is: How do I get the first visible html element in a WebBrowser?
You may say that the updated html will not have the memorized element anymore. Right. But I have timestamps in the document and will use the memorized html element to find the best position in the new html doc.
I think I found the right method to use. There are actually two possibilities to retain the scroll position when the document is being refreshed.
Assume the following members:
WebBrowser _browser;
HTMLDocument HtmlDoc { get { return (HTMLDocument)_browser.Document; } }
(1) If the document didn't really change (in my example only changed in style) I use the current scroll position to auto-scroll after an update:
before refresh:
_scrollPos = ((IHTMLElement2)(HtmlDoc.documentElement)).scrollTop;
after refresh:
HtmlDoc.parentWindow.scrollTo(0, _scrollPos);
(2) If the document has changed I use the left upper element of my document (that is of known structure)
before refresh:
IHTMLElement el = HtmlDoc.elementFromPoint(50, 0);
Do some magic with that el (requires knowledge of the doc) and remember some string that can be used to search for the best element after the update.
string beforeRefresh = fromElement(el);
after refresh use the remembered string and search for the best html element in the reloaded html doc.
IHTMLElement newEl = fromString(beforeRefresh);
newEl.scrollIntoView(true);
So the actual method I was missing was elementFromPoint(). The rest is "custom logic".
I'm trying to figure out how to bind a javascript event to a select element in GWT, however the select element isn't being built in GWT, but comes from HTML that I'm scraping from another site (a report site from a different department). First, a bit more detail:
I'm using GWT and on load, I make an ajax call to get some HTML which includes, among other things, a report that I want to put on my page. I'm able to get the HTML and parse out the div that I'm interested in. That's easy to display on my page.
Here's where I get stuck: On the portion of the page I'm using, there's a select element which I can easily locate (it has an id), but would like to capture event if my user changes that value (I want to capture changes to the select box so I can make another ajax call to replace the report, binding to the select on that page, and starting the whole process again).
So, I'm not sure how, once I get the HTML from a remote site, how to bind an event handler to an input on that fragment, and then insert the fragment into my target div. Any advice or pointers would be greatly appreciated!
How about this:
Element domSelect = DOM.getElementById("selectId");
ListBox listBox = ListBox.wrap(domSelect);
listBox.addChangeHandler(new ChangeHandler() {
void onChange(ChangeEvent event) {
// Some stuff, like checking the selected element
// via listBox.getSelectedIndex(), etc.
}
});
You should get the general idea - wrap the <select> element in a ListBox. From there, it's just a matter of adding a ChangeHandler via the addChangeHandler method.