Need to enter Text - c#

I tried finding the element using Get but it does not work, thats why i treid with GetElement method
I am trying to enter text in an textbox element found using GetElement in teststack white using C#
i want to know how to cast the automation element to UIitem so that i can do enter() or click operation on that element
var all = appWindow.GetElement(SearchCriteria.ByControlType(ControlType.ComboBox)
.AndByText("Model collapsed"));
var element = all.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.NameProperty, "Edit Box collapsed"));
element.enter("");
when i do element.enter or click it gives error, i think i need to cast it or is there any other way where i can achieve this. Thank you.

After using the below code i was able to enter text.
var all = appWindow.GetElement(SearchCriteria.ByControlType(ControlType.ComboBox)
.AndByText(parentValue));
var element = all.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, childValue));
TextBox textBox = new TextBox(all, appWindow.ActionListener);
TestStack.White.InputDevices.AttachedKeyboard keyboard = appWindow.Keyboard;
textBox .Click();
keyboard.Enter("test");

Related

How to click browser and input into textbox?

How I can click buttons with ids or anything other, input to text box string etc. I know in windows form is easy with getelementbyid. But in WPF I cant find anything. I know how get source to string but I cant make click. Any ideas how do this or is even possible? I can get list of Ids from source +regex. Or is there too something I can get simply list? Need something like this:
HtmlElement button = webBrowser1.Document.GetElementById("lButtonSearch");
button.Click += new HtmlElementEventHandler(GotoSearchPage);
I can do something like this but what next, how display it?
System.Windows.Forms.WebBrowser weba = newSystem.Windows.Forms.WebBrowser();
weba.Navigate(new Uri("www.google.com"));
string testowo = "btnI";
System.Windows.Forms.HtmlElement htmlElement = weba.Document.GetElementById(testowo);
htmlElement.InvokeMember("click");
How now convert it to display lets say WebBrowser id is =browserwindows
browserwindow=weba
wont work
Try this:
var doc = webBrowser1.Document as IHTMLDocument2;
var button = doc.all.OfType<IHTMLInputElement>().FirstOrDefault(b => b.name == "btnG");
if(button != null)
{
((IHTMLElement)button).click();
}

Spinner clear value exception in Selenium c# Webdriver

I want to test this popup window:
but for spinner I get exception. I tried these codes but non of them worked.
Actions componentProportion = new Actions(driver);
componentProportion.SendKesy(Kesy.Control+"a");
componentProportion.SendKeys(editNumber,"2356").Build().Perform();
When I run this code nothing happens and it also causes problem for new text box(Display Title) code and it doesn't work properly.
//Edit display title
IWebElement editDt = driver.FindElement(By.XPath("//*[#id='cmp_display_title']"));
editDt.Click();
Thread.Sleep(500);
editDt.SendKeys(Keys.Control + "a");
editDt.SendKeys(Keys.Delete);
Thread.Sleep(500);
editDt.SendKeys("hello");
And if I want to use this code:
IWebElement editNumber = driver.FindElement(By.CssSelector("something"));
editNumber.Click();
Thread.Sleep(1000);
editNumber.SendKeys(Keys.Control+"a");
I get this exception:
ElementVisibleException : element not visible
Is there anyway to solve this problem? Thank you for your help.
So, since your elements are in frame, in order to be able to work with them you need to switch to that frame first (usually by name)
//Switch to required frame
driver.SwitchTo().Frame("ContentContainer");
// find your elements and do the actions
// This is how you switch to the default page
driver.SwitchTo().DefaultContent();
As I noticed, you want to replace the display title input text with some new text
In order to clear the text, you dont need to simuale ctrl+a.
Simply, use this code to set new value to your text element :
IWebElement editDt = driver.FindElementById("cmp_display_title");
editDt.SendKeys(""); // clears the text
editDt.SendKeys("your new text");

How to retrieve text from a TextBox that was created programatically

Alright, so I have a form set up that contains a label and a button. When the button is pressed it creates several labels and and two textfields in a specific area.
I cannot for the life of me, figure out how to retrieve the text from those textfields and store it in a public string.
Any help would be wonderful and greatly appreciated.
Edit: As per request.
TextBox playertextbox = new TextBox();
playertextbox.Location = new Point(460, 200);
this.Controls.Add(playertextbox);
You can assign a name to the textbox and later use ControlCollection.Find to retrieve it
Try this
TextBox playertextbox = new TextBox();
playertextbox.Location = new Point(460, 200);
playertextbox.Name = "playertxtBox"; // Add some name
this.Controls.Add(playertextbox);
Then use the name in the button click handler or similar :
//Use that name to search here
TextBox playertextbox = ((TextBox) this.Controls.Find("playertxtBox",true)[0]);
string text = playertextbox.Text;

C# code behind Required validation

I am writing a c# code for a Required field validator for a Multiline text box.
I have a issue in the run time:
when i won't enter any text inside the
text box
For first Click on submit (Button) it shows the error message
For second Click on submit it won't validate the text box and the form is submitted.
Same two issues when i even enter any
text inside the text box.
Overall it is not validating...
Please help me on what could be the possible bug in the below code.
txtReport = new InputFormTextBox();
txtReport.TextMode = TextBoxMode.MultiLine;
txtReport.RichText = true;
txtReport.RichTextMode = SPRichTextMode.Compatible;
txtReport.Rows = 5;
txtReport.Width = new Unit(200);
txtReport.ID = "txtReport";
txtReport.Text.Trim();
this.Controls.Add(txtReport);
reqVal = new RequiredFieldValidator();
reqVal.ID = "reqVal";
reqVal.ControlToValidate = txtReport.ID;
reqVal.SetFocusOnError = true;
reqVal.ErrorMessage = "*Comments field is mandatory";
reqVal.Enabled = true;
this.Controls.Add(reqVal);
Thanks in advance
From what it sounds like you are not re-adding the validator after the first submit, causing the second submit not to validate. But it's hard to tell from the fragment you posted (in what event/method is this being called?).

How to programmatically click on text input in WebBrowser using C#

I have opened a website using WebBrowser. Now I would like to programmatically click input text (textbox) field. I can not use focus because this website uses JS to unlock this field only if it's clicked and I've tried also this:
Object obj = ele.DomElement;
System.Reflection.MethodInfo mi = obj.GetType().GetMethod("click");
mi.Invoke(obj, new object[0]);
But it returns mi = null. How to do this so it will work?
Very similar to my answer on your other question.
Get an HtmlElement respresentative of your textbox, and call HtmlElement.InvokeMember("click") on it.
If you can, use:
webbrowser1.Navigate("javascript:document.forms[0].submit()")
or something similar. For me, it's been much easier and more accurate.
To fill-up a text field on a webpage:
string code ="";
code = code + "var MyVar=document.getElementById('tbxFieldNameOnWebPage');if(MyVar != null) MyVar.value = 'SOMEVALUE';";
domDocument.parentWindow.execScript(code, "JScript");
Then To Click a button on a webpage:
code = "";
code = "var SignupFree = document.getElementsByTagName('button')[1];";
code = (code + " SignupFree.click();");
domDocument.parentWindow.execScript(code, "JScript");
you can also use document.getElementById('buttonID'); instead of document.getElementsByTagName('button')[1]; but an id must be provided for this button on that particular webpage.
Use InvokeMethhod on HtmlElement or Browser.InvokeScript function.

Categories

Resources