I'm trying to create a program that will programmatically complete a form.
The payee field on the form uses a searchable listbox.
I'm using the code below to place the text in the drop down box, but it's not activating it as though it was searched and selected from the list.
webBrowserWB.Document.GetElementById("select2-chosen-4").InnerText = payee;
How would I mimic key strokes to type the value that I need placed in that field? Or is there another option?
Example of the list box is in the image below. Values don't appear until the user begins typing in the field.
Edited to include HTML
<div class="select2-drop select2-display-none select2-with-searchbox
select2-drop-active" id="select2-drop" style="display: block; left:
6.5px; width: 781px; top: 240px; bottom: auto;">
<div class="select2-search">
<label for="s2id_autogen4_search" class="select2-
offscreen">Payee</label>
<input type="text" autocomplete="off" autocorrect="off"
autocapitalize="off" spellcheck="false" class="select2-input"
role="combobox" aria-expanded="true" aria-autocomplete="list" aria-
owns="select2-results-4"id="s2id_autogen4_search" placeholder="">
</div>
<ul class="select2-results" role="listbox" id="select2-results-4"><li
class="select2-no-results"></li></ul></div>
Rather than using the WebBrowser control, I was able to resolve my issue by using Selenium.
Related
I am building a web application in ASP.NET using webforms.
I have an input html element which I have set to run at server and I want to fire an event whenever the date is changed.
<input id="datePicker" class="form-control" style="display: inline; margin-left: 5px; width: 15%; text-align: center;" type="date" runat="server" onserverclick="Date_Changed"/>
I have the event in my codebehind:
protected void Date_Changed(object sender, EventArgs e) {}
However, the event is never fired.
Don't believe that server side click events can be wired up to a input that way (using the onserverclick).
I would consider dropping in a HTML button, say like this:
<button id="datePicker"
class="form-control"
style="display: inline; margin-left: 5px; width: 15%; text-align: center;"
type="date"
runat="server" onserverclick="Date_Changed" />
And even better yet, drop in a asp.net button.
If you drop in a input tag, then I don't think you can get the asp.net system to wire this up for you. You could I suppose write this:
(this is what a plane jane above button becomes:
<input onclick="__doPostBack('Button11','')"
name="Button11" type="button" id="Button11" value="button">
So you could try above - but using a "input" tag I don't believe will work, but try a HTML button as per above - that does allow "on server click".
Do keep in mind that if you drop in a asp.net text box, and set textmode = "date"?
Say like this:
<asp:TextBox ID="MyDateTest" runat="server" TextMode="date">
</asp:TextBox>
Then you see this:
So, above is a built in feature - you don't need any js, bootstrap, or anything at all.
but, you could add a "client" side click to your markup, as I posted a above the do post-back would (should) run your click event. However, it probably a whole lot better to not fight asp.net, since then you quite much hand coding a lot of HTML, and doing that means you quite much toss out most of the features of why you would use asp.net in the the first place (that means to take advantage of all the built in controls, and the pre-processing of those controls for you).
I need to select values (any value from House_TypeList) from dropdown menu with NUnit or just pure selenium. .
They are not seen in HTML.
I have tried select by xpath, by name, by span contains etc etc, I tried sending down key. I have waited for the element to become visible. I am out of ideas. Nothing works. I have not tried yet moving the cursor and trying to select it by that, but had a few problems implementing it and having in mind my luck, not really believing it will work either..
I am a beginner here, maybe I did some mistakes there. But I successfully managed any other inputs, buttons, navigation..
I have checked other similar questions, but could not find the answer that would work for me.
Is it even possible here?
Source:
<div class="dx-item dx-box-item" style="display: flex; min-height: auto; flex-grow: 1; flex-shrink: 1;"
<div class="dx-item-content dx-box-item-content" style="width: auto; height: auto; display: flex; flex-direction: column; flex-basis: 0px; flex-grow: 1;">
<div class="dx-first-col dx-last-col dx-field-item dx-field-item-required dx-col-0 dx-flex-layout dx-label-h-align">
<label class="dx-field-item-label dx-field-item-label-location-left" for="dx_dx-...._typeId">
<span class="dx-field-item-label-content" style="width: 159px;">
<span class="dx-field-item-label-text">Type:</span>
<span class="dx-field-item-required-mark"> *</span>
</span>
</label>
<div class="dx-field-item-content dx-field-item-content-location-right">
<div class="dx-textbox dx-texteditor dx-texteditor-empty dx-dropdowneditor-button-visible dx-widget dx-dropdowneditor-field-clickable dx-dropdowneditor dx-selectbox dx-validator dx-visibility-change-handler" id="slb_HouseManagement_EditHouse_TypeList">
<div class="dx-dropdowneditor-input-wrapper dx-selectbox-container">
<input type="hidden" value="" name="typeId">
<div class="dx-texteditor-container">
<input autocomplete="off" id="dx_dx-4e..._typeId" class="dx-texteditor-input" aria-haspopup="true" aria-autocomplete="list" type="text" readonly="" spellcheck="false" tabindex="0" aria-expanded="false" role="combobox" aria-required="true">
<div data-dx_placeholder="Select..." class="dx-placeholder"></div>
<div class="dx-texteditor-buttons-container">
<div class="dx-dropdowneditor-button dx-button-normal dx-widget" type="button">
<div class="dx-button-content">
<div class="dx-dropdowneditor-icon"></div>
</div></div></div></div></div></div></div></div></div></div>
Done. Found it in Devextreme support, the user had a bit different problem, but it solved mine as well.
IWebElement selectedItem = driver.FindElement(By.XPath("//div[#role='option']/div[text()='Apartment']"));
selectedItem.Click();
The DOM you have provided here does not contain any element for Lists. So I cannot share exact working code here. I will share few sample which you can update and use
With Selenium to select items from a list, you have two options to choose from:-
Select Class
Make an object of select class like below
Select obj =new Select(driver.findElement(By.id("search-box")));
Then you can use several functions on this select obj
obj.selectByVisibleText("Apartment");
Or
obj.selectByIndex(2);
or
obj.selectByValue("Farmhouse");
You can also get all the element in a List and then work around that list
List <WebElement> myHouseList = obj.getOptions();
System.out.println(myHouseList.size());
2.Actions Class
driver.manage().timeouts().implicitlyWait(10 , TimeUnit.SECONDS);
ele= driver.findElement(By.linkText("HouseList"));
Actions act = new Actions(driver);
act.moveToElement(ele).click();
WebElement webele = driver.findElement(By.linkText("Apartment"));
act.moveToElement(webele).click().build().perform();
Hope this helps you!!
I have a telerik grid in my mvc application with a edit button.
When I click on this button I get another template from SharedTemplates based on the same model of the grid view.
In my editor template, if I declare a field using this:
#Html.EditorFor(a => a.Order)
Html generated:
<input class="text-box single-line valid" id="Order" name="Order" type="text" value="000020">
As you can see, I got the order value from the grid when I clicked on the edit button. But if I declare the same field not using the model, like this:
<input type="text" id="Order" name="Order" style="width: 100px; background-color: lightgrey" />
Html generated:
<input type="text" id="Order" name="Order" style="width: 100px; background-color: lightgrey">
Basically, the question is: Why if I put #Html.EditorFor(a => a.Order) I get the order value when I click edit, and I cannot get the order value when I use the
input type="text" id="Order" name="Order" style="width: 100px; background-color: lightgrey" />
I hope that someone can help me with issue.
In a DNN custom module that I'm creating, I have a RadButton that doesn't show the Text value from the resource file. Other controls do read the values from the resource file.
I tried from the ascx and from the code behind. Another strange thing is that when debugging the application from the code behind I see the Text attribute.
the control definition is:
<dnn:dnnRadButton ID="CntUsSubmit" runat="server" OnClick="ProcessSendMail" resourcekey="CntUsSend"
SingleClick="true" SingleClickText="Submitting..." Style="clear: both; float: left; margin: 10px 0;" ></dnn:dnnRadButton>
inse Page_Load I make the localization (too):
CntUsSubmit.Text = Localization.GetString( "CntUsSend.Text", LocalResourceFile );
the page is rendered as:
<span id="dnn_ctr474_View_CntUsSubmit" class="RadButton RadButton_Default rbSkinnedButton"
style="clear: both; float: left; margin: 10px 0;">
<input class="rbDecorated" type="button" name="dnn$ctr474$View$CntUsSubmit_input"
id="dnn_ctr474_View_CntUsSubmit_input" value="" />
<input id="dnn_ctr474_View_CntUsSubmit_ClientState"
name="dnn_ctr474_View_CntUsSubmit_ClientState" type="hidden" />
</span>
the Sys.Application.add_init function shows:
Sys.Application.add_init(function() {
$create(Telerik.Web.UI.RadButton, {"_accessKey":"","_postBackReference":"WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('dnn$ctr474$View$CntUsSubmit', '', true, '', '', false, true))","clientStateFieldID":"dnn_ctr474_View_CntUsSubmit_ClientState","iconData":{},"imageData":{},"singleClick":true,"singleClickText":"שולח...","toggleStatesData":[],"uniqueGroupName":"","uniqueID":"dnn$ctr474$View$CntUsSubmit","value":"שלח"}, null, null, $get("dnn_ctr474_View_CntUsSubmit"));
});
I understand the control knows the Text from the add_init, but the rendered button doesn't get the it. Can someone help me how to solve this?
I'm using DNN 7.0.2, VS 2012, for Framework 4.0
That's odd. You could try the following in its OnClientLoad event:
function OnClientLoad(sender, args)
{
sender.set_text(sender.get_text());
}
Try alerting the get_text() first to see if it retursn what you need. If so, you can put this in a global JS file and add the event handler through a Theme.
If this doesn't help try putting the desired text in a hidden field (e.g. with a unique class) and again use the set_text() method.
In the end I gave up with RadButton, instad I used Encosia's Postback Ritalin which made the trick nice and smoothly.
I have a <td> like this
<td valign="middle" class="table_td td top" style="width: 347px">
<div id="Style" style="position:absolute;">
<img src="images/additional-keywords-image.gif" style="background: middle right;">
</div>
<span class="feature_text" style="cursor:pointer;" onmouseover="ShowPicture('Style',1)" onmouseout="ShowPicture('Style',0)" id="a1"> Featured Merchant Ad </span><br />
<span class="feature_text_small">(Merchant Ad in Home Page,<br /> for valuable Site Exposure)</span>
Div id="Style" has image bigger than the <td>. AIm is to show the image in div when the moveover happens on the first span. The image shows up fine. But, i want the vertical center of div picture to be at the span with id= "feature_text" and has text "Featured Merchant Ad". I have tried but could not succeed. Where am i doing wrong?
I am not sure if i understod your question correctly, if you want to center the image in the div#style
You dont need this in img
style="background: middle right;"
Try
style="margin:auto;";
and adding this to div#style (div with id style)
style="vertical-align:middle; text-align:center;
Try with:
<div id="Style" style="position:absolute;">
<img src="images/additional-keywords-image.gif" style="background: middle right; position: relative; top: -20px;">
</div>
You are gonna have to play with the top value to get the vertical centering just right (the amount depends on the height of img).