Click button in WebBrowser control vb.net - vb.net

I am trying to click the button highlighted in picture below. The code is from a web page:
I'm not to sure, but I believe the button is within an iFrame.
I have tried:
Dim wrapClick As HtmlElement = Contact.WebBrowser1.Document.GetElementById("Btn_WrapUp")
wrapClick.InvokeMember("Click")
And:
Dim elPoint As New Point(704, 340)
Dim wrapClick As HtmlElement = Contact.WebBrowser1.Document.GetElementFromPoint(elPoint)
wrapClick.InvokeMember("onClick")
And:
Contact.WebBrowser1.Document.GetElementById("Btn_WrapUp").InvokeMember("Click")
In all of the above, I have tried 'onClick' and 'Click'.
WebBrowser1 is on a different form.
Thanks!

Click button in WebBrowser control - working example:
Main file with frame - x.html:
<html>
<body>
<iframe width="400" height="300" src="y.html" id="frame1"> </iframe>
</body>
</html>
File placed in frame - y.html - with submit button:
<html>
<body>
<form action="...some_action...">
<input type="submit" id="btn"> Submit!
</form>
</body>
</html>
Button on VB form with OnClick event:
Dim Frame1 As HtmlWindow = WebBrowser1.Document.Window.Frames("frame1")
Frame1.Document.GetElementById("btn").InvokeMember("click")
VB2010Ex & .NET Framework 4 Client Profile.
I have tried code with action that load other site. Site was loaded in iframe.
Finally success :-)

Related

C# Selenium Webdriver (Firefox) iFrame does not allow text to be entered via sendKeys

I'm using latest Selenium Firefox (2.53.0)
Previously code was working when performing the following
1) Finding the iFrame by Xpath iframe class
IWebElement detailFrame = `Driver_Lib.Instance.FindElement(By.XPath("//iframe[#class='cke_wysiwyg_frame cke_reset']"));`
2) Switching to that frame by
Driver_Lib.Instance.SwitchTo().Frame(detailFrame);
3) finding the p tag within the iFrame by
IWebElement freeText = Driver_Lib.Instance.FindElement(By.TagName("p"));
4) Inserting a simple string to the iframe text box
freeText.SendKeys("this is some text");
5) switching from the iFrame back to the main contentwindow by
Driver_Lib.Instance.SwitchTo().DefaultContent();
Here is the code part from the application
<iframe class="cke_wysiwyg_frame cke_reset" frameborder="0" src="" style="width: 100%; height: 100%;" title="Rich Text Editor, ctl00_ctl00_MainContentPlaceHolder_PageContent_mlcEditor_CKEditor" aria-describedby="cke_61" tabindex="0" allowtransparency="true">
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<title data-cke-title="Rich Text Editor, ctl00_ctl00_MainContentPlaceHolder_PageContent_mlcEditor_CKEditor">Rich Text Editor, ctl00_ctl00_MainContentPlaceHolder_PageContent_mlcEditor_CKEditor</title>
<style data-cke-temp="1">
<link href="https://myUrl/contents.css" rel="stylesheet" type="text/css">
<style data-cke-temp="1">
</head>
<body class="cke_editable cke_editable_themed cke_contents_ltr cke_show_borders" contenteditable="true" spellcheck="false">
<p>
<br _moz_editor_bogus_node="TRUE">
</p>
</body>
</html>
</iframe>
The test I am running is a simple one, open up that page, insert some text, save.
It not inserting the text into the iFrame. I am totally puzzled as to why.
Has anyone else found this issue at all?
Many thanks
I have removed the exception, this was a redHerring.
the iFrame can not have text entered into it
hi all I've found the solution:~ here is the summary of what was happening:
1) The iFrame was being located by xPath.
2) the SwitchTo() method used placed focus in the detailFrame instance of IWebElement
3) What was not happening was the p tag could not be located as it was contained withing a CSS Body Class that.
The solution was staring me in the face the whole time! so simple!!
I did this:
IWebElement detailFrame = Driver_Lib.Instance.FindElement(By.XPath("//iframe[#class='cke_wysiwyg_frame cke_reset']"));
Driver_Lib.Instance.SwitchTo().Frame(detailFrame);
IWebElement freeText = Driver_Lib.Instance.FindElement(By.TagName("body"));
freeText.SendKeys("This is a free text question created by Automation Smoke Test");
Driver_Lib.Instance.SwitchTo().DefaultContent();
So as you see, simply locating the 1st instance of the body tag!

VB.NET - Click Login Button on Webbrowser page

I'm trying to click a submit button on a website, I'm doing it via element by id:
webbrowser1.document.getelementbyid("Enter").invokemember("submit")
Website button:
<input value"Enter" type="submit" />
But its not working
Would appreciate some help,
Thanks
EDIT :
For Each htmls As HtmlElement In WebBrowwer1.Document.All
If htmls.GetAttribute("value").ToLower = "enter" Then
htmls.InvokeMember("click")
End If
Next

VB.net Can you read the text in a certain Div

I was wondering if you read text in a certain div so when the html code says:
<html>
<head>
</head>
<body>
<div id="Main">SomeText</div>
<div id="Text">Welcome to my website</div>
</body>
</html>
i only want to see 'Welcome to my website' in the textbox 1.
is there anyone who knows how i can do that?
any help would be much appreciated.
Mark your div with runat="server":
<div id="TextDiv" runat="server">Welcome to my website</div>
then access the text in VB.NET code:
TextDiv.InnerHtml
I would recommend the HTML Agility pack hosted on codeplex at http://htmlagilitypack.codeplex.com/. With it you can connect to a HTML source, load the HTML into an reasonably friendly navigator and use XML type queries to traverse and manipulate the HTML.
I would use HtmlAgilityPack, then it's easy as:
Dim html = System.IO.File.ReadAllText("path")
Dim doc = New HtmlAgilityPack.HtmlDocument()
doc.LoadHtml(html)
Dim welcomeDiv = doc.GetElementbyId("Text")
Me.TextBox1.Text = welcomeDiv.InnerText

pass form data to a new window

I'm trying to figure out how to pass form data collected from sql database to a new window. The idea is when the user click 'Rediger' (edit), that a new small window will open up with the current data and an input field for the user to change the data, and then hit the save button for the data to be written to the database. Then the window must close and the original page being updated with the new data. Is this possible? Can anyone please help me with this? Thank you.
Check out the page here: http://kristoff.it/onlinecoaching/coach/
Here is my dummy code:
<!DOCTYPE html>
<html>
<head>
<script>
function getValue()
  {
var txtfield=document.getElementById(this.id);
//alert(txtfield.innerHTML);
newWindow.document.write(txtfield.innerHTML);
return newWindow;
//windowsize(640, 480)
  }
</script>
</head>
<body>
<form method="POST" id="submitform">
<label id="name">John Smith</label><input type="button" id="button" onclick="getValue()" value="Edit">
<br>
<label id="title">Director</label><input type="button" id="button" onclick="getValue()" value="Edit">
</form>
</body>
</html>
You'll need some AJAX for this.
First follow this discussion, to be able to detect when the windows was closed.
Then make an ajaxRequest like this:
$.ajax({
url: "someUrlWhereYouCanFindTheUpdatedRecords.html",
cache: false
}).done(function( html ) {
//Some code that updates your webpage
});
Note that this code is using JQuery
Good luck!

Is it possible to execute a JavaScript function loaded in a WebBrowser control at any moment in AutoHotkey?

I thought InvokeScript may work but it didn't.
strHTML =
(
<!DOCTYPE html>
<html>
<head>
<script> function displayDate() { document.getElementById("demo").innerHTML=Date(); }</script>
</head>
<body>
<p id="demo" onclick="displayDate()">This is a paragraph. Click here.</p>
</body>
</html>
)
new WebBrowser(strHTML)
Class WebBrowser
{
__New(strHTML) {
static WB
Gui, New, Resize
Gui, Add, ActiveX, vWB w780 h580 , Shell.Explorer
Gui, show, w800 h600
WB.Navigate("about:blank")
Loop
Sleep 10
Until (WB.readyState=4 && WB.document.readyState="complete" && !WB.busy)
WB.Document.Write(strHtml)
; WB.Document.Close()
WB.document.InvokeScript("displayDate")
; WB.document.parentWindow.document.InvokeScript("displayDate") ; does not work
return this
GuiClose:
ExitApp
}
}
There are at least two ways that you can call the function:
WB.document.parentWindow.execScript("displayDate()")
WB.document.parentWindow.displayDate()
All global functions within the script are available as methods of the window object.
The WebBrowser control referred in the article you linked to is part of the .NET Framework, and is not the same as the WebBrowser control you are using. This is why attempting to call InvokeScript raises an "Unknown name" error message.