There are a bunch of websites with "search" input boxes.
If I input a word manually then it automatically search without need to click any buttons.
Using the following code:
GeckoInputElement input = (GeckoInputElement)geckoHtmlElement;
input.Value = "searchword";
The I see that search input box is filled but nothing happens automatically.
If I manually add space or any character then website works as expected.
Auto searches my wanted word.
I tried using input.Focus(); but still same.
Any ideas how I can input text into search box in a more advanced way or something like that?
I think the solution here is to manually trigger the event that triggers the search - for example the keyup event. I had the same problem which I solved by adding this code:
nsAStringBase eventType = (nsAStringBase)new nsAString("keyup");
var ev = browser.Document.CreateEvent("HTMLEvents");
ev.DomEvent.InitEvent(eventType, false, false);
nameBox.GetEventTarget().DispatchEvent(ev);
You would need to inspect your page and see if there are any javascript events attached to your input.
Good luck!
Related
I am working on a project which is Analysis of Papers from Google Scholar. What I do is basically, parsing the HTML, storing related fields into database etc. However, I am stuck at a point, while I am taking the Titles of the publications, I realized, I am able to get first twenty elements. But, there are sixty papers in related account:
http://scholar.google.com/citations?user=B7vSqZsAAAAJ
So, I think as a solution, I need to click to the 'show more' button programmatically, so I can have all the Title's, Publication Venue etc.
What do you think? How can I perform that kind of action?
Edit: I checked the 'show more' button, while there is nothing to show as a next page, its html code still remains same. As a solution I can use loop for n times. However, I am looking for more robust solution.
Thank you for your time!
If it is clicking on a button within a WebBrowser control on a Windows Form Application, then 'Yes' you can do it.
There are ways of getting more control over identification by using XPath.
(You might need to use Javascript to use XPath for object interactions - since you haven't asked for that, I will assume you don't need it)
webBrowser.Navigate("http://www.google.com");
// Or
HtmlElement textElement = webBrowser.Document.All.GetElementsByName("q")[0];
textElement.SetAttribute("value", "your text to search");
HtmlElement btnElement = webBrowser.Document.All.GetElementsByName("btnG")[0];
btnElement.InvokeMember("click");
Or even typing into text boxes with
webBrowser1.Document.GetElementById("gs_tti0").InnerText = "hello world";
If its this website specifically, there is a simple workaround. Change the query string to what records you want.
http://scholar.google.com/citations?user=B7vSqZsAAAAJ&cstart=0&pagesize=2000
I am writing Coded UI Test's for a web app. I am having problems such as I record actions using the test builder, however sometimes the button that is clicked has different information each time I run the test and as result VS can't find the button.
The html code never changes so what I want to do is find the button by its html code and click it that way.
For example on Google the path to the search button is
<button id="gbqfba" aria-label="Google Search" name="btnK" class="gbqfba"><span id="gbqfsa">Google Search</span></button>
How can I click this button using the code above or Alternativly using the XPath
//*[#id="gbqfba"]
Any help would be greatly appreciated.
adjust the Search Properties and Filter Properties.
Something like:
$('button span').each(function(){
If($(this).html() == "Google Search")
{
$(this).parent('button').click();
}
});
I found the answer, If you go to the UIMap.uitest file and click the method you have the problem with you can change the filter properties and the search properties to remove parts that are failing your test.
This will do the trick:
BrowserWindow.ExecuteScript("$('#gbqfba').click();");
I'm just using watin to fill some textfields but sometimes it writes in the wrong textfield because the textfields name is not clear here's my code
IE browser = new IE(site);
browser.TextField(Find.By("type","text")).TypeTextQuickly(username.ToString());
browser.TextField(Find.By("type", //"password")).TypeTextQuickly(pass.ToString());
browser.Button(Find.By("type", "submit")).Click();
Edit your HTML code and setup ID´s for your input elements. Then use Find.ById
One option could be to see if there is an outer element (such as a Div) you can find first, and afterwards get the text fields from that element instead of from the browser variable. That could for instance look like this:
Div div = browser.Div(Find.ById("divId"));
//Div div = browser.Div(Find.ByClass("divClass")); // or like this for instance...
TextField text = div.TextField(Find.By("type", "text"));
TextField password = div.TextField(Find.By("type", "password"));
Button submit = div.Button(Find.By("type", "submit"));
I am unclear as to your knowledge of WatiN and testing so I will start from the begginging. First you need to go on the webpage you want to test and (in IE) go to tools -> Developer tools. Click the white arrow in the menu then proceed to click the box you wish to utilize. Once you do this the developer tools will give you the code for the textbox including many ways you can reference it in your code. For example, using dev tools in IE I can automate logging into my gmail like this:
IE browser = new IE("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=http://mail.google.com/mail/&scc=1<mpl=default<mplcache=2");
browser.TextField(Find.ByID("Email")).TypeText("myemail#email.com");
browser.TextField(Find.ByID("Passwd")).TypeText("mypassword");
browser.Button(Find.ByID("signIn")).Click();
There are many Find.By commands so there is no reason you can't acess ANY textfield you wish. You just need the html and to be specific to which one you want to write into. I hope this helps :)
I have a Ajax auto complete extender attached to TextBox control. When the user starts typing the suggestive options are displayed in the divsion underneath. Getting the suggestion from a webservice call. On OnClientItemSelected="GetCode" I am using the below JavaScript to get the selected suggestion text into the search box.
Now I want the ENTER click to activate the search.
If the user selects from the suggestions he is getting and clicks the enter. It works fine. It activates the search. This is the code I am using.
function GetCode(source, eventArgs) {
var txtValue = document.getElementById('<%=txtAutoComplete.ClientID%>');
txtValue.value = eventArgs._value;
//$('#<%= txtAutoComplete.ClientID %>').val(eventArgs._value);
$('#<%= ImageButton1.ClientID %>').click();
}
But The problem is if the user doesnt select from the suggestion and types some text and clicks the enter key Doesnot activate search. Yes I know that It doesnot call the GetCode Function.
I am not getting how to do this. Anyone Please help me..
I am want something exactly like in www.laterooms.co.uk
You have to set a default button for either the form or the text field.
I got this Text box with default value as "First Name" ..Now when I click inside this text box to enter name , this value "First Name" keeps on displaying. What I want is to the text box to clear as soon as I click inside it. What property do I need to set in mt textbox tag ?
[Edit]
ok anything from Telerik that I can use to do that ?
There is not out of the box functionality in TextBox that will accomplish this, but the ASP.Net Ajax Toolkit has a Watermark Extender that will do everything you want.
I have used both, but now personally use a jQuery Watermark Plugin
Either will work just fine, choose based on your needs.
According to the Telerik docs you just have to set the EmptyMessage property on their TextBox control. Demo Page Here
In the code behind, on Page Load you can add the following code to achieve this
TextBox1.Attributes.Add("onClick", "javascript:if(this.value=='First Name'){this.value='';}");
You can use the method suggested by #Josh. If you do not want to use Ajax Toolkit controls or JQuery you could write it on your own using Javascript. Write a function which gets called when the foucs is received by the textbox control. I thik the function is called onfocus or just focus in Javascript.
Hi I just wrote this small function which will achieve your desired result
function clearInputBox(x,prefil){
if(x.value == prefil){
x.value = '';
}
}
Your input box looks like this
<input type='text' value='First Name' onfocus="clearInputBox(this,'First Name')" />
May be this will help you
Taking Shobans advice one step farther, you could add something like this to your Page subclass
protected override void OnInitComplete(EventArgs e)
{
string jsString = "javascript:if(this.value=='" + TextBox1.Text + "'){this.value='';}";
TextBox1.Attributes.Add("onFocus", jsString);
base.OnInitComplete(e);
}
What this will do is, it will always consider that default string is the one this controll contains at esign time (the initial one in your .aspx file), so you wont have to manually change it in codebehind every time you change your .aspx. Remember, that OnIinitComplete fires before any viewstate or postback data has been applied, but after the controlls on your page have been set to their default values.
P.S. As anishMarokey pointed, use onFocus vs onClick, since fields can gain focus without clicks via Tab key.