that's my first question, i hope i'm doing everything correctly.
Anyway, i have a weird issue. I basically have this HTML input which i want to fill with WatiN :
<input name="edit[id]" class="form-text required" id="edit-id" type="text" size="60" maxlength="64" value="">
That's my code in C# :
IE ie = new IE();
ie.GoTo(urlhere, just too long);
ie.TextField(Find.ByName("edit[id]")).TypeText("Text");
It's not working and it returns this exception :
Ulteriori informazioni: Could not find INPUT (hidden) or INPUT (password) or INPUT (text) or INPUT (textarea) or TEXTAREA element tag matching criteria: Attribute 'name' equals 'edit[id]' at about:blank
I'm not sure why it gives "at about:blank" honestly. I tried with a random google page and the code it's working. If i put a random name instead of the correct one, it gives me the same exception but with the correct url instead of "about:blank".
Note : I'm trying to fill a form.
Thanks for your help!
Not sure what web page are you using but from the information you posted it looks like that form might be "somewhere else" (another div, frame, etc.) To be able to find the EXACT entry you should press F12 (IE) or CTRL+SHIFT+I (Chrome) and traverse the HTML web page to find the exact portion were the input lies and you will find the exact spot.
The code you posted is perfectly fine, there's nothing else you need to do to make it work. If you need more help, posting the webpage you are trying to use will go a long way (if possible, of course).
Related
I need to find the input box in this HTML:
<div id="employeesDataTable_filter" class="dataTables_filter">
<label>
<input type="search" class="form-control input-sm"
placeholder="Filter..." aria-controls="employeesDataTable">
</label>
</div>
But for the life of me cannot - please help,
I have successfully written bags of tests and found many page element of different types but this one has stumped me.
I am very new to this and have tried
By ExecutiveSearchBox = By.XPath("//input[#type='search' and
class='dataTables_filter']");
You have encountered problems because you are selecting class attribute on input node instead on div. Try following selector:
//div[#class='dataTables_filter']//input[#type='search']
Also as #Marco Forberg mention it is good to use contain() XPath function in case if there are multiple classes provided for element:
//div[contains(#class, 'dataTables_filter')]//input[#type='search']
I hope it'll help to resolve your issue :)
To find the input element in your html snippet, you simply use
FindElement( By.CssSelector( "input" ) )
But note:
not always is the input box editable after page load is completed, it may take some time. It might be wise to wait until the box becomes editable if you want to send data to it.
not always does the input box appear immediately in the DOM. With modern UI like Angular, it might be not there immediately, might be something else for a while and only later become an input field and the like. Also here, making use of Seleniums wait functionality sure is a good idea.
I ALWAYS wait for the DOM state I expect and only after some time when the state is not achieved I throw.
I am trying to do registration for this site
Registration page is inside a popup page.
HTML Code:
<fieldset>
<label>Username:</label>
<input name="username" required="" type="text"/>
</fieldset>
When I try to find the element using below tried code, element is not getting find.
driver.FindElement(By.XPath(".//*[#id='load_form']/fieldset[1]/input")).SendKeys("Kal");
I have also tried this with using CssSelector, but facing the same issue.
driver.FindElement(By.CssSelector("div#load_box form#load_form input[name=username]")).SendKeys("kal");
When I execute above code, I have got an error like element not visible
Can anyone help me on this issue?
Try this below code using xpath locator
driver.FindElement(By.XPath("//input[#name='name']")).SendKeys("Kal");
Explanation of xpath:- Use name attribute of <input> tag.
Suggesstion:- Instead of using absolute xpath, use relative xpath.
Note:- Before reach to this web-element provide some few seconds of wait, so your driver may able to find the web-element. So, you will not get an error like element not visible
Use below xpath:
//*[#id='load_form']/fieldset[6]/input[#name='username']
that site has 2 forms with the id load_form so you're getting the first one which isn't visible since it's the login form. You want the second one which is the register form.
you can use a selector to grab one of the fields that exists on the registration page and then move up to it's parent form and get all descendants that are fieldsets to fill out.
Here is the xpath you can use to pass the text "Dev" into the field labelled with "Name".
driver.findElement(By.xpath("//div[#class='fancybox-overlay fancybox-overlay-fixed']//form[#id='load_form']/fieldset/input[#name='name']")).sendKeys("Dev");
Let me know if this answers your question.
The problem is that there are two username INPUT fields. The way I typically handle this is to find a parent of the element that I want that has an ID or something unique that will distinguish the two elements. In this case, you can use a simple CSS selector,
#load_box input[name='username']
Note the load_box ID that distinguishes the two INPUTs.
Ajax popup on way2automation site is a tricky one because if you look for the username field by name By.name("username"), you will end up with 2 elements - one for username from signup popup, one from singin popup. To avoid this you have to explicity mention the correct element. This can be done via the following code:
webDriver.get("http://way2automation.com/way2auto_jquery/index.php");
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("a[href='#login'"))).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".ajaxlogin input[name='username']"))).sendKeys("my_username");
As you can see in the code I am using class of the login popup - .ajaxlogin. I have used Java, but the concept is the same - you have to refer to the username element via css selector with popup class included: By.cssSelector(".ajaxlogin input[name='username']")
I am using Selenium in C# to Enter data into textboxes on a webpage:
But i am getting this error:
OpenQA.Selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
I'm using #name, but there are 2 controls on the page with name="MinPrice"
heres the HTML:
<div class="form-group for-sale">
<label>Min Price</label>
<input class="form-control" name="MinPrice" min="0" placeholder="Minimum Price" value="" type="number"></input>
and this is the xpath I'm using:
txtMinPrice = Driver.Instance.FindElement(By.Name("MinPrice"));
I also tried using XPath, but similar results:
txtMinPrice = Driver.Instance.FindElement(By.XPath("//input[contains(#name,'MinPrice') and type='number']"));
If anyone has any type of idea....this is driving me nuts.
ElementNotVisibleException exception occurs when selenium can find an element in the DOM but it is not rendered on the screen.
When I have encountered this error before it has been generally caused by one of three things:
Selenium is trying to interact with an object that is present in the DOM but has not yet rendered on the screen, in which case you might consider adding some type of delay. (Avoid sleep if you can but it is useful for debugging)
The element is below the visible screen, in which case you would need to scroll to interact with it.
There is an overlapping element that is blocking the display of the element.
Add a sleep(10) in to make sure everything on the page has loaded first before any user actions are preformed. If that doesn't work also add
driver.manage().window().maximize() at the start of your test to make sure all the page elements is in view.
If that doesn't work its your xpath. Try something like //*[#class="form-group for-sale"]/input
Or use the Firefinder add on in mozilla firefox to check your xpath is valid and exists on the page.
Selenium is good at scrolling down to view an item, but when it comes to Scrolling back up it's a PiA, and usually throws that exception. I usually just do something like
element.SendKeys(Keys.Home);
Thread.Sleep(100);
I have a webpage with 2 search fields (top and bottom) and some text in-between them and I want to send a query to the bottom field. Both fields are identical (same code).
I tried storing the bottom one in a variable and use that variable to send the keys, but somehow it always sends the text to the first one.
var bottomSearch = _WebDriver.FindElements(By.Id("inputBox"))[1];
Assert.IsTrue(bottomSearch.Displayed);
bottomSearch.Clear();
bottomSearch.Click();
bottomSearch.SendKeys("test");
bottomSearch.SendKeys(Keys.Enter);
So: Clear() works and properly deletes any text already present in the bottom search, Click() also works, SendKeys sends text to the top searchbox and SendKeys(Keys.Enter) goes back to the bottom one and presses Enter from there.
I use the firefox driver and also tried selecting the element by CssSelectors or other identifiers but did not work.
Any help or ideas are most appreciated!
Thank you!
Here is the code for the search fields:
<div class="searchbox-input">
<input id="inputBox" class="querybox" type="text" placeholder="Entrer le terme recherché" name="inputBox" value="test">
</div>
OK, so after 2 days of trial and error I asked the website's devs to change the id of the bottomSearch and now everything works well.
After all these tries I'm tempted to suspect a bug in the driver or the SendKeys() method, but since I failed to found any reference to back this up and I successfully dealt with same ID fields before, maybe it's just something in the website's implementation or mine.
So in conclusion, follow the best practice advices and this should never happen :)
i want create small web browser , tiny and fast
but i have problem ,
let me explain :
1 - user enter site : google.com
2 - c# program get google.com
3 - find <td nowrap="" align="center">
4 - in web browser only show that area
i dont know where i must start ,
thanks
Ok, I'm going to try answer your question, but I am deciphering as well.
Create a WebBrowser control on your form. (2.0 is fine for what you need) and .Navigate("http://www.google.com");
Get the source code from the Document. You can do this as follows: string source = _WebBrowser.Document.Body.OuterHtml;
Use string manipulation to get to the area on the page you need. For instance .SubString() functions
Save the text into a file, or stream and load it into the WebBrowser control, or replace the pages Document HTML with just the HTML you are wanting to show.
Okay! Looking at the comment it seems you want to request for a page using c# and show only one part of the page. In your case its that specific <td> . Please correct me if I am wrong.
Other than what Kyle has mentioned. Check out HTML agility Pack. It might be of interest to you.