How do I chose the next best option - vb.net

I have a vb program which uses the built in web browser to find a specific drop down menu on a site and chose the size which the user has entered. The website changes the value for each different item so I must find the correct option using the following code:
Dim element As HtmlElement = WebBrowser1.Document.GetElementsByTagName("select").Cast(Of HtmlElement).First(Function(el) el.GetAttribute("name") = "size")
element.GetElementsByTagName("option").Cast(Of HtmlElement).First(Function(el) el.InnerText = Form1.cmbSize1.Text).SetAttribute("selected", "selected")
This works to set the dropdown menu to the correct size if it is available but if for example the user enters size as : 'Small' and it isn't present I would like the program to add the next size for example : 'Medium'
<select id="size" name="size">
<option value="26881">Medium</option>
<option value="26882">Large</option>
<option value="26883">XLarge</option>
</select>
By default the website loads with the default size 'Medium' if the user entered size but I have a function which adds the item to the users cart afterwards and if the size entered isn't present for some reason it will not add to the cart
the code for adding to cart is:
For Each addtobasket As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
If addtobasket.OuterHtml.Contains("add to basket") Then
addtobasket.InvokeMember("click")
Return
End If
Next
Thanks in advance :)

Related

wait for element to be enabled protratcor

Again, this question might be easy or already asked but i am not able to find any answer to this. All i get is to check if element is clickable but that is not working for me.
Is there any simple solution to wait for an element until it becomes enabled. I have set of dropdowns in my application and other dropdown get selectable only when value is selected in previous dropdown.
I tried below code but it is not working.
var element = element(by.css('[id*="uxSeries"] select'));
browser.wait(protractor.ExpectedConditions.elementToBeClickable(element), 10000);
Error message i am getting:
Failed: stale element reference: element is not attached to the page
document
HTML for dropdown before it get enabled:
<select name="GalleryControl$uxSeries" onchange="OnChangeScript" id="uxSeries" disabled="disabled" style="width:215px;">
<option selected="selected" value="">All Series</option>
<option value="Value1">Option1</option>
<option value="Value2">Option2</option>
<option value="Value3">Option3</option>
<option value="Value4">Option4</option>
<option value="Value5">Option5</option>
</select>
After i select value in my first dropdown, disabled="disabled" property goes away from dropdown.
Can i wait for browser until it is enabled or Disabled property is no more?
Failed: stale element reference: element is not attached to the page document
This exception occurred due to changing of element, as you are saying I have set of dropdowns in my application and other dropdown get selectable only when value is selected in previous dropdown means when it's getting enable, it changes their position or some attribute value may be disabled attribute become change that's why you're in trouble.
You should try first to wait until this element become stale from disabled state using protractor.ExpectedConditions.stalenessOf(), then find again this element when it is in enable state as below :-
var EC = protractor.ExpectedConditions;
#find disabled select element first
var disabledSelect = element(by.css("select#uxSeries[disabled='disabled']"));
#now wait until this becomes stale from disabled state
browser.wait(EC.stalenessOf(disabledSelect), 10000);
#now find enabled select element
var enabledSelect = element(by.css("select#uxSeries"));
#now do your further steps

#Html.DropDownListFor - How to set different color for a single item in list?

I wish to have one item in my DDL to be a different color (red). However the list comes from a table and is not hard coded in the page like
<option value="Option 1">Option 1</option>
but rather as
#Html.DropDownListFor(r => r.Journal.Frequency, Model.JournalFrequencyList, "Select a Frequency", new { #class = "form-control" })
Is there a way to make just one item a different color?
You can update your styles/css to make one item red color. Now you did not specify which specific item you want. With jQuery, you can select a specific option and set the color of that to red.
Assume your razor view renders a SELECT element like this
<SELECT id="fancySelect">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</SELECT>
And if you want to set the color of the option which has value attribute set to "2", you can use the below code
$(function(){
$("#fancySelect option[value='2']").css('color','red');
//you can also apply a css class if needed
});
If you want to update a different option, update your jQuery selector to get that.
EDIT : As per the comment
is there any way to use the text as opposed to the value? Example
change if text is "Deleted"
You can update your jQuery selector to get the option with a specific text.
$("#fancySelect").find("option:contains('Deleted')").css('color','red');
I suggest you rely on option value than the text, you can set the value as a code which you can program against.

Selecting an item from a dropdown doesnt trigger any action with VB.net

I'm trying to automate loading data using vb.net, but there comes a point where I select values of various combobox. Seeing the code of the page I find that the combobox has a format similar to this(its just an example):
<select id="BirthMonth" name="BirthMonth">
<option value="">Month</option>
<option value="01" >January</option>
<option value="02" >February</option>
<option value="03" >March</option>
<option value="04" >April</option>
fails to work with WebBrowser1.Document.GetElementById ("Name combo") SetAttribute ("OPTION", "March"), searching the Internet I found a solution where inter is a parameter that contains the value.:
Public Sub selector(ByVal inter)
Dim option_ As HtmlElementCollection
option_ = WebBrowser1.Document.GetElementsByTagName("option")
For Each option__ As HtmlElement In option_
If option__.InnerHtml = inter Then
option__.SetAttribute("selected", "True")
End If
Next
End Sub
which if you choose value, but the page does not take it, so it does not refresh the other Combobox.
Anyone know how to do to select the value, so the page can trigger the action?
PS: must be in the name of the field by value.
Thank you very much
Bye!
PS: I solved the problem just adding this lines after the selection:
WebBrowser1.AllowNavigation = True
WebBrowser1.Document.Forms(0).InvokeMember("submit")
Its solved just adding this lines after the selection:
WebBrowser1.AllowNavigation = True
WebBrowser1.Document.Forms(0).InvokeMember("submit")

dijit/form/select to select search fields in Arc JS API

I'm brand new to javascript, dojo and HTML and I've searched everywhere for examples of this and cannot find any.
I have a map with some feature points and a find task to highlight the feature points on the map, and display them in a grid with it's field attributes. This works great when I specify the search field as:
findParams.searchFields = ["LOCATION"];
But if I add:
findParams.searchFields = ["LOCATION", "MODEL_NUM"];
The grid displays results from multiple fields (ie. searching for attributes in LOCATION "A" would also find attributes in MODEL_NUM containing the letter "A"). So I decided to add a drop down menu select to specify which field to search in (one at a time) so the results are more precise.
So I added the following dijit:
<select id="fieldSelect" data-dojo-type="dijit/form/Select" name="fieldSelect">
<option value="" selected="selected">Select a field</option>
<option value="MODEL_NUM">Model Number</option>
<option value="LOCATION">Location</option>
<option value="NUM_DEFICIENCIES">Number of Deficiencies</option>
<option value="INSTALL_DATE">Install Date</option>
</select>
I then modified the search field statement to:
findParams.searchFields = "[" + "\"" + dom.byId("fieldSelect").value +
"\"" + "]";
When I click my search button I get an Uncaught TypeError: a.join is not a function (FindParameters.js:5)
I hope this is enough information. Does anyone have a solution or a recommendation?
UPDATE
After a suggestion to pass an array and not a string to the findParams.searchFields, I made the following changes:
findParams.searchFields = [];
findParmas.searchFields.push(dom.byId("fieldSelect").value);
This still gave me attribute results from multiple fields. After running a couple small tests:
var selectedField = document.getElementById('fieldSelect').value;
var index = selectedField.options[selectedField.selectedIndex].value;
And:
var selectedField = dom.byId('fieldSelect').value;
I'm finding that in the Chrome developer tools debugger, when I created a breakpoint at that line and executed the statement, both examples had the value of selectedField as 'undefined'.
Is this an issue of not getting the value from the drop down select dijit?
If no value is passed to findParams.searchFields, the API assumes all fields are valid, which is why I'm getting attribute results from multiple fields.
Thanks.
Use dijit.byId instead of dom.byId.
The following works for me:
var value = dijit.byId("fieldSelect").value;
if ("" != value) {
findParams.searchFields = [value];
} else {
findParams.searchFields = ["MODEL_NUM", "LOCATION", "NUM_DEFICIENCIES", "INSTALL_DATE"];
}
I found the problem.
Ultimately it was the registry.byId that led me to the answer, I had to rearrange some code after I realized the searchFields was in the wrong function and not in the function that is called when I click the search button.
But when accessing the dijit, the only thing that worked was registry.byId to access the dijit node and pass the value of the selected value into my searchFields.
Thanks.

Selenium 2 - getting the selected option from drop down list

<select class="selectCity">
<option></option>
<option value="Paris">Paris</option>
<option>New York</option>
<option>London</option>
</select>
Select op1 = new Select(driver.findElement(By.xpath("(//*[#id='cityTable']//*[contains(#class,'selectCity')])")));
List<WebElement> allSelectedOptions = op1.getAllSelectedOptions();
WebElement firstSelectedOption = op1.getFirstSelectedOption();
System.out.println("op1!!!!!"+firstSelectedOption.getText());
The user selected option on the web page is London.
Put the output is op1!!!!!
How to find the option that has been selected on the web page?
Thanks in advance!
Selenium.getSelectedLabel("//string locator");
The above code helps in knowing the option witch is currently selected and visible from the drop down list.
String locator of drop down box can by anything eg:- name,id,xpath
EG : Selenium.getSelectedLabel("name=productIdxSel");