Get WebBrowser Control to Check Radio Option - vb6

I want my vb6 program to check radio option and submit it through a PHP page. I have the following code:
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If WebBrowser1.LocationURL = "http://xx.xxxxxxxxxx.com/vb6.php" Then
WebBrowser1.Document.frmC.cid.Value = "52821558"
WebBrowser1.Document.frmC.instrument.Value = "CL"
'WebBrowser1.Document.frmC.ctype
WebBrowser1.Document.frmC.Submit.Click
End If
End Sub
"ctype" in the code above represents the name of the radio option and bellow its HTML code
<INPUT TYPE="Radio" Name="ctype" value="Buy"><span style="font-size: 14px">Buy</span>
<INPUT TYPE="Radio" Name="ctype" value="Sell"><span style="font-size: 14px">Sell</span>

Use SetAttribute:
Dim radio As Object
Set radio = WebBrowser1.Document.frmC.ctype.Item(0)
radio.SetAttribute "checked", "checked"
Use .Item(0) for the first radio & .Item(1) for the second.

Related

Selenium: Form is not visible even after Wait is applied

I'm practicing Selenium with MVC application that has partial view.
When the page is rendered, I see the form displayed:
<form action="/MyScreen/SaveData?Length=20" data-ajax="true" data-ajax-complete="handleComplete" data-ajax-failure="CheckError" data-ajax-loading="#loader" data-ajax-method="POST" data-ajax-mode="replace" data-ajax-update="#partialPlaceHolder" id="TicketDetailForm" method="post" novalidate="novalidate">
<div id="partialPlaceHolder" style="width:100%;">
<div id="Ticket-Details"></div>
</div>
</form>
This form has a button I need to click.
I'm using Wait to make sure the form is displayed before I click on the button:
WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement ticketForm = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("TicketDetailForm")));
boolean isForm = ticketForm.isDisplayed();
When executing the above code, I'm getting the following error:
Expected condition failed: waiting for visibility of element located
by By.id: TicketDetailForm.
I modified the code to get the elements gradually and was able to locate the form and a placeholder where the Button is rendered.
I'm using Wait to locate a content of the form:
List<WebElement> forms = renderBody.findElements(By.tagName("form"));
WebElement placeHolder = forms.get(0).findElement(By.xpath("//div[#id='partialPlaceHolder']"));
WebElement ticketDetail = placeHolder.findElement(By.xpath("//div[#id='Ticket_Details']"));
I cannot locate ticketDetail `WebElement
What might that be?
You can check if the form partial view is displayed by checking its element list size and then click the button which you want to click when the list size > 0
For example:
boolean partialViewDisplayed = false;
List<WebElement> partialViewElement= driver.findElements(By.id("Ticket-Details"));
while(!partialViewDisplayed){
if(partialViewElement.size()>0){
//Mark the boolean partialViewDisplayed true
partialViewDisplayed = true;
}
}
//Perform the further operations from here

MVC: Allow multiple click of the same button

Is it possible to allow multiple clicks on a sigle submit button of a form? I have a form where I want to perform an action on the first submission (first click) and a different action on the second submission (second click).
I am basically using ajax to populate a div in the form during the first submission and I want to submit the form on the second click.
I have tried to put by button in the div to by updated, and after the first click, I update update the div and re-creating the button in the updated div. But if I use this method, how can I set the action method of the newly created button in my controller method for Ajax?
My controller method returns something like
return Content( mystring + <input type='button' value='continue submission'/>
if i use this approach, how do I set the action method of the buttton, or is there another way of doing this?
Use two buttons with JavaScript:
Button 1 is shown initially. On click, it hides itself, shows button 2, and performs your action 1.
Button 2 is hidden initially. It is unhidden by button 1 and on click, it performs your second action.
This looks a little weird but I can tell you how to do this. Take an input type="submit" and make it hidden. Have a variable as var flag = false; When user first clicks you input type="button" call a function and do your stuff and make sure to make the flag=true; In the function itself check if flag=true; the trigger the event of your input type="submit".
Like as follows:
<input type="button" id="btn1" onclick="perfromAction()" value="submit"/>
<input type="submit" id="btn2" value="submit" style="display:none"/>
<script type="text/javascript">
var flag=false;
function performAction()
{
if(flag){
$("#btn2").trigger("click");
}
else{
//do processing
flag=true;
}

submit button link based on drop down option selected, opens in new tab

I'm using a script solution I found here, by #clops (clops) that sets the onclick value of a submit button in a form, based on a item selected in a dropdown list. Everything in the script is working as it should, however I would like to open the new window in a new tab on click of the button. Also it would be nice to have the submit button disabled until an option in the list is selected. Any feedback would be helpful. Thanks.
Current script and HTML is below:
<script>
function goToNewPage() {
if(document.getElementById('target').value){
window.location.href = document.getElementById('target').value;
}
}
</script>
<form name="dropdown">
<select name="selected" id="target" accesskey="E">
<option selected>Select...</option>
<option value="http://www.google.com/">Google</option>
<option value="http://www.search.com/">Search.com</option>
<option value="http://www.dogpile.com/">Dogpile</option>
</select>
<input type="button" value="Go" onclick="goToNewPage(document.dropdown.selected)">
</form>
Nothing an author can do can choose to open in a new tab instead of a new window.
you could open it in new window as following
window.open(url,'_blank');
where the URL is your target form the drop down list
to disable submit button until an option in the list is selected, check this link

KnockoutJs + Jquery Plugin Validation

Using KnockoutJS + JQuery Validation, all the control validation is working fine. While Radio btn validation is not working.
Issue 1: * is displayed near to radio btn
Male
Female
output: * Male Expected output : Male *
output: * Female Expected output : Female *
Issue 2: While applying Class=Required both radio buttons are mandatory, how we will resolve the issue
Issue 3: Same thing happend for dynamic radio buttons as well. All are available in the same page.
Guide me......
Try the knockout validation, it works so much nicer together with knockout
https://github.com/ericmbarnard/Knockout-Validation
Make sure your radio buttons have the same "name" attribute (this is the case with jquery validation regardless of using knockout)
You only need to add required class to one of them if you do my first point above
Dynamic radio buttons need to have specific names (and names need to be same for all buttons you want to validate in a group)
For instance, I have this foreach loop that validates the radiobuttons correctly because they have unique names
<input type="radio" data-bind="attr: { name: 'options-' + $index() }" class="required" value="Yes" checked />
<input type="radio" data-bind="attr: { name: 'options-' + $index() }" value="No" checked />

How to tell the control if the button of the view is dis/enabled

In my view I have this button:
<input type="submit" value="Delete" disabled="disabled" id="btnDelete" name="btnDelete" />
and I have Jquery method which makes it enabled.
This is in the view.
How to check if the button is enabled or disabled in the controller?
I have this method:
public void MyMethod(FormCollection form)
{...}
but form doesn't contain anything about the button.
also, form["btnDelete"] is null.
Yes because input button can not hold any value and returning it is useless.
If you want to have that attribute value in your controller make a hidden input which hold the button value on page load and will be changed on btnDelete click event.

Resources