I'm trying to make some code on VB.net that opens a website and logs in, and after that runs a report. Everything has been working fine when I try to get any of the from the website, but the ones that have this instruction within the OnClick property = "return oamSubmitForm('inputParamView:paramForm','inputParamView:paramForm:_idJsp106');"
Basically, if you see the following code, you see that I click on some of the CheckBoxes and it works just fine, but when I retrieve the button, it doesn't type an input, it actually has the link of the website when I use a whatc while debugging.
This is my code (I skipped the login section):
Private Sub open Page()
ieb = New SHDocVw.InternetExplorerMedium()
ieb.Navigate("http://example.example/qptheme2/pages/index.faces")
ieb.visible = True
ieb.Silent = True
While Not (ieb.ReadyState = WebBrowserReadyState.Complete)
Application.DoEvents()
End While
If v.checked = False Then
v.Click()
End If
v = ie.Document.GetElementById("inputParamView:paramForm:inputParametertuesday")
If v.checked = False Then
v.Click()
End If
v = ie.Document.GetElementById("inputParamView:paramForm:_idJsp106")
v.Click() '<-- IT FAILS HERE Exception HRESULT: 0x800A01B6
If I check the watch it shows mshtml.HTMLAnchorElementClass {http://example.example/qpreport/savedpages/savedReports.faces#}
if I check the source code from the page, this is the element that I'm trying to get:
<a id="inputParamView:paramForm:_idJsp106" onclick="return
oamSubmitForm('inputParamView:paramForm','inputParamView:paramForm:_idJsp106');" href="#"
I don't know if it has anything to do with the property OnClick.
I will appreciate any of your help trying to solve this issue.
I found the solution by myself. I just had to instance the element I was retrieving as mshtml.HTMLAnchorElementClass
after that, I was able to click on it.
Dim l As mshtml.HTMLAnchorElementClass = ieb.Document.GetElementById("inputParamView:paramForm:_idJsp106")
l.click()
Related
I am using the below mentioned code for automation of Edge Browser
The code is working fine except for "If then Else" block.
The complete script is as follows
Dim Obj As New WebDriver
' search for company - SF 1cr and above
Sub EdgeAutoSF1CRA0()
Set Obj = New Selenium.EdgeDriver
Dim ele As WebElement
Dim By As New Selenium.By
Obj.SetCapability "ms:edgeOptions", "{""excludeSwitches"":[""enable-automation""]}"
Obj.Start "edge", ""
Obj.Get "https://*********************"
Obj.Window.Maximize
Obj.FindElementByName("croreAccount").SendKeys ("Search")
Obj.FindElementByXPath("//*[#id='loadSuitFiledDataSearchAction']/div[1]/div[3]/div[4]/img").Click
Obj.FindElementById("borrowerName").SendKeys (ThisWorkbook.Sheets("Sheet1").Range("C5").Value)
Obj.FindElementByXPath("//*[#id='search-button']/ul/li[1]/div/input").Click
Obj.Wait 30000
If Obj.FindElementByCss("#downloadReport").Attribute("Style" = "display") = "none" Then
Obj.FindElementByXPath("//*[#id='three-icons']/ul/li[3]/a/div").Click
Else
Obj.FindElementByXPath("//*[#id='downloadReport']/div").Click
End If
End Sub
In the If then Else statement I want to search for the style attribute of the id "downloadReport" for "display :none"
The code on website is < a href="downloadStatusReport" id="downloadReport" style="display: none;"><div class="download-icon">Download</div></a>
However, code always evaluate the statement as False and proceeds to execute the command "Obj.FindElementByXPath("//*[#id='downloadReport']/div").Click"
The attribute name is style, not capitalized Style.
You can construct the locator so that the desired style value will be a part of locator itself.
You can use FindElements instead of FindElement so it will return you a list of matching elements so as if such element found it will return a non-empty list, otherwise it would be an empty list. With this you can check if returned list is empty or not, as following:
If Not IsEmpty(Obj.FindElementsByCss("[id='downloadReport'][style*='none']")) Then
Obj.FindElementByXPath("//*[#id='three-icons']/ul/li[3]/a/div").Click
Else
Obj.FindElementByXPath("//*[#id='downloadReport']/div").Click
End If
In short, there is no merit in locating an element with style attribute set as display: none;. Even through you locate the element, you won't be able to click on it. So the If-Then-Else logic won't work as intended.
Instead find the desired element which is visible and enabled element, so you can invoke click on it.
I am working on google reverse image,Now i design code for initial click and after first click i want to assign image url on google page but unable to assign image url to on web form.Following is my code,suggestion required regarding how to assign image url for search purpose.
Dim d As WebDriver
Set d = New ChromeDriver
d.Start "Chrome"
d.Get "https://www.google.com.pk/imghp?hl=en&
Sleep 3000
d.FindElementByXPath("/html/body/div[1]/div[3]/form/div[1]/div[1]/div[1]/div/div[3]/div[2] /span").Click
d.Timeouts.ImplicitWait = 5000
d.FindElementByCss(".nfyh2c").SendKeys "https://canadiantire.scene7.com/is/image/CanadianTire/0653145_1?defaultImage=image_na_EN&wid=160&hei=160&op_sharpen=1 "
I resolve my issue using below mentioend code and updating my chrome webdirver,driver should same as your current chrome browser version.
Set myelement = d.FindElementById("Ycyxxc", timeout:=0, Raise:=False)
If myelement Is Nothing Then
MsgBox ("no element found")
Else
myelement.SendKeys ("https://canadiantire.scene7.com/is/image/CanadianTire/0580385_1?defaultImage=image_na_EN&wid=160&hei=160&op_sharpen=1")
End If
I'm trying to populate a form on a webpage that uses Knockout JS. When I insert a value into a particular text box it appears to have taken the value but when I submit the form it retains it's previous value. With a bit of digging around I've discovered that Knockout JS uses data-binding to update the underlying value. When I insert a value into the input text box the Knockout JS is not being triggered and therefore not updating the underlying value. This post is for something similar but with a check box and dropdown box rather than a text box. But I can't figure out how to get it working with a text box.
The actual website I'm trying update requires a login, however I think this page on the Knockout JS Site http://knockoutjs.com/examples/helloWorld.html will suffice for testing purposes.
Basically what I need is, using VBA, to enter a FirstName and LastName in the 2 text boxes (where it currently says 'Planet' and 'Earth'). You should see the 2 input values appear immediately below where it says 'Hello Planet Earth'. Typing it manually into the text boxes works fine. But I just can't get it to work in VBA.
Here' what I have so far...
Sub KnockoutTest()
Dim IE As New InternetExplorer
Dim hDoc As HTMLDocument
IE.Visible = True
'Load webpage and loop until loading is complete.
IE.Navigate "http://knockoutjs.com/examples/helloWorld.html"
Do While (IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE)
DoEvents
Loop
Set hDoc = IE.Document
Set firstName = hDoc.getElementsByClassName("liveExample").Item(0).all.Item(1)
Set lastName = hDoc.getElementsByClassName("liveExample").Item(0).all.Item(3)
firstName.Click
firstName.Value = "Joe"
lastName.Click
lastName.Value = "Bloggs"
'Close ie object
Set IE = Nothing
Application.ScreenUpdating = True
End Sub
Anyone got any ideas on how I get the knockout events to fire?
The actual html from the text box on the page I'm trying to update is this....
<input type="text" ondrop="return false;" onpaste="return false;" data-bind="numericValue: Markup, visible: IsCellEditable(), selected: IsCellEditable(), event: { blur: blurZoneMarkup, keypress: function (data, event) { return $parent.isDecimal(data, event, hdnIsDiscount) }, keydown: function (data, event) { $(event.target).data('tabcode', event.which || event.keyCode); { return true; } } }" style="width: 90%; display: none;">
Any help or advice would be much appreciated. I've been trying to solve this for 3 days now!
Basically, you would need to handle such automated inputs as 'HTMLevents' and trigger them. An updated snippet from your original code:
With hDoc
Set evt = hDoc.createEvent("HTMLEvents")
evt.initEvent "change", True, False
firstName.Value = "Joe"
firstName.dispatchEvent evt
End With
Tested this code and works fine for the website that link that you have provided.
I have done tons of website automations with VBA and the most robust approach is to create one event, specific to each field that you would want to fill, assign a value to the field, and dispatch the event that you have created.
For further information, refer to the documentation on MSDN https://msdn.microsoft.com/en-us/ie/ff975247(v=vs.94)
I'm automating an application using Selenium so what is happening is when the script runs and it hits the login button an error comes up in the top right which stops further execution. What I want is need a way by which i can capture this "error message" so that I would know the cause of the halt of the application execution.I'm attaching the image of error and also the code that I have tried but it didnt work.
#FindBy(xpath="//*[#id='toast-container']/div/div]")
static WebElement errorMessage;
WebDriverWait wait = new WebDriverWait(CommonBrowserSetup.driver, 15);
wait.until(ExpectedConditions.visibilityOf(errorMessage));
String mess=errorMessage.getText();
System.out.println(mess);
If you want to capture Unknown error occured
Just try the following code and let me know if it works for you.
After the login button is clicked add the following:
WebElement Error = driver.findElement(By.xpath("//div[contains(text(),'Unknown error occured')]"));
if(Error.isDisplayed()){
String Errormessage = Error.getText();
System.out.println(Errormessage);
}
Just as the title says. I have code that disables all controls that runat=server. Its as follows
Dim c As Control
For Each c In pc
If c.HasControls Then DisableAllControls(c.Controls)
If c.GetType.ToString.ToLower.IndexOf("webcontrols.dropdownlist") > -1 Then
DirectCast(c, DropDownList).Enabled = False
ElseIf c.GetType.ToString.ToLower.IndexOf("webcontrols.textbox") > -1 Then
DirectCast(c, TextBox).Enabled = False
ElseIf c.GetType.ToString.ToLower.IndexOf("webcontrols.radiobuttonlist") > -1 Then
DirectCast(c, RadioButtonList).Enabled = False
ElseIf c.GetType.ToString.ToLower.IndexOf("webcontrols.radiobutton") > -1 Then
DirectCast(c, RadioButton).Enabled = False
ElseIf c.GetType.ToString.ToLower.IndexOf("webcontrols.button") > -1 Then
DirectCast(c, Button).Enabled = False
End If
Next
But I have a couple of href's in there that i want to disable also. I know they dont runat server, so how can i catch these?
You can add runat="server":
<a runat="server" href="..." ></a>
It is the only way to maintain controls using server side code.
You can add runat="server" to HTML controls too. Without it you won't be able to access the control on the server side and you won't be able to disable it.
That code looks invalid (If c.HasControls Then DisableAllControls(c.Controls) has no matching End If) but perhaps VB.NET has added inline If syntax like that without me realising.
Anyway, as far as disabling all runat="server" controls, you should be able to just do this:
For Each c as WebControl In pc.OfType(Of WebControl)()
' Put your recursive call here as before
c.Enabled = False
Next
Now, to "disable" those other elements, you can either add runat="server" to them (perhaps not even possible if you have generated HTML), or you can use some JavaScript. I'm going to assume by disable you mean hide in the case of <a> tags?
jQuery makes this easy, with a sample script being something like:
$(document).load(function() {
$('a').hide();
});
or:
/* hides all a tags under an element with class="someClass" */
$(document).load(function() {
$('.someClass a').hide();
});
You could then have your code render this script, using something like this in your Page:
Dim script as String = "" /* your javascript here */
Me.ClientScript.RegisterClientScriptBlock(Me.GetType(), "HideTagsScript", script)