I am not able to clear_text in selenium - c#

This is the link ->https://www.w3schools.com/js/tryit.asp?filename=tryjs_alert
I need to remove the texts which I have mentioned in that image
I have used this path for locating the area
By.id("textareaCode");
but not able to delete. If I perform these action it was showing INVALIDEXCEPTIONSTATE.
Could please someone help me to remove the texts using selenium webdriver.

You could try this:
IWebElement element = driver.FindElement(By.Id("textareaCode"));
element.Clear();
Please remember that you need to wait for page to load. I hope it'll help you :)

Related

C# Selenium: Click button under iframe

I have a iframe modal under my site. I am trying to click button in
it but I am unable to do so. Below is my code. Please let me know
what am i missing
driver.SwitchTo().Frame(driver.FindElement(By.Id("iframeid='frame_name'")));
driver.FindElement(By.Id("sendReuqest")).Click();
Expected Result: Button id: sendRequest should get clicked which is on iframe
Actual Result: Element is not found.
Please let me know if you have any questions.
Try to do it this way. Let's take frame_name id as iframe_1. Whatever you frame id is you can add instead of iframe_1. Also you have a spelling mistake (typo) it might be sendRequest so I am adding as id of your button.
driver.SwitchTo().Frame(driver.FindElement("iframe_1")));
driver.FindElement(By.Id("sendRequest")).Click();
Hope it works. Please do comment and let us know.
Best of luck.
It looks like you're trying to use By.Id() when you should be using By.CssSelector(). By.Id() expects you to pass a parameter which matches the ID element in the HTML.
driver.SwitchTo().Frame(driver.FindElement(By.CssSelector("[iframeid='frame_name']")));
driver.FindElement(By.Id("sendReuqest")).Click();
Try that one:
driver.SwitchTo().Frame("frame_name");
driver.FindElement(By.Id("sendReuqest")).Click();

Selenium: Finding page element in WordPress

Ok, this should be easy, but I cannot seem to figure it out:
How do I identify and access the new post area (from the Dashboard) in WordPress, using selenium in VS/.Net?
I can access the title field easily by ID, like this:
Driver.Instance.FindElement(By.Id("title")).SendKeys("Sometitle");
But, looking at the page source, I cannot figure out how to access the post body.
In recent versions, I believe, there was an iframe, and it could be accessed like this:
Driver.Instance.SwitchTo().Frame("content_ifr");
Driver.Instance.SwitchTo().ActiveElement().SendKeys(body);
...but this doesn't work anymore, and looking at the source it seems that this has been changed.
So - does anyone know how to do this in recent versions of WordPress?
EDIT: It turns out that I was wrong; there IS indeed an iframe named "content_ifr". So the new question is: Why doesn't the above code work? It's supposed to switch the focus to the content frame, but it doesn't.
try
Driver.FindElement(By.XPath(""));
to find XPath in google chrome right click on element->Inspect element, then click on "Copy XPath".
Hope it helps!

Identifying elements in Iframe after content change using Selenium

The Problem
I have an iframe which Contains a form , once I submit the form the content of the iframe changes to something else based on the information . So I need to verify the elements/texts in result as a part of my test
What I did
I used Switch().Frame to submit the data to iframe , and used " WebDriverWait " to wait for results (I am waiting for an element )
The issue
After submission new elements do not get recognized and "wait for element" fails after time out even though the result screen visually loaded to the iframe ( I also tried increasing the time out , but no luck )
Am i doing something wrong ? or Can anyone give me suggestion ?
highly appreciate any help
I am working on the same scenario and this is working for it, you can try :
driver.switchTo().frame(frameid);
driver.findElement(By.cssSelector("input[name=\"login\"]")).click();//whatever you want to perform in frame.
driver.switchTo().defaultContent();
Thread.sleep(3000);
driver.switchTo().frame(frameid);
driver.findElement(By.cssSelector("input[name=\"login\"]")).getText();//Whar ever you want to perform.
If you have any concern so let me know.
Enjoy!
I think after submission - the element get changed now the element do not lie in iframe.
Use:
driver.switchTo().defaultContent();
And try recognizing element.
I am not pretty much sure. but can you give it a try.
Is the complete form loading again or just some text/info that you are providing?

Selenium webdriver actions on element will be executed in wrong location

I'm trying to build my first test with selenium and got a problem.
I'm searching for a element, no problem. I can click on it, get the
text in the element... every thing works fine.
But double click on the element just doesn't work. Selenium
clicks in the wrong location. I made a screenshot of this situation:
Screenshot
To find the row i use xpath and search for the text in the cell, but this text is unique(I checked it)
private readonly string _identityPath = ".//td[.= 'All Employees']";
...
mainPage.FindElement(By.XPath(_identityPath)).Click(); //Works(dotted box)
Actions builder = new Actions(mainPage);
IAction doubleClick = builder.DoubleClick(mainPage.FindElement(By.XPath(_identityPath))).Build();
doubleClick.Perform(); //wrong location/element
/*
Actions action = new Actions(mainPage);
action.DoubleClick(mainPage.FindElement(By.XPath(_identityPath)));
action.Perform(); *///wrong location/element
This page is in an iframe and the grid is a dojo component... maybe the problem
comes from there. Any ideas whats wrong? I have no idea where this is coming from. :/
Greets
It is common issue that Actions builder does not work.
Using JavaScript should help - find answer in this thread:
Selenium 2/Webdriver - how to double click a table row (which opens a new window)
If the element is in an iframe, you need to switch to that iframe in order to interact with the element.

Try to get for WatiN for links/browsers

I've recently started to test and use WatiN, and i came across some of problems/errors that i cant really solve.
First ill describe what i'm doing with my tests ..
I'll go and get all the links in a specific div in a list ... so i have a link lists ... which im gonna loop thru ...
In the loop im gonna use a link.clicknowait() function, to open that link (it opens in a new ie tab) .. then i sleep thread for like few seconds and i close that browser by attaching that link (url) to a new browser and after that the browser is closed as im using it always with 'using (..)' statement.
So the first problem is that when the browser gets all the links and start to click them one of the links might lead not the right page, meaning like it can lead to a page that is saying page doenst exist anymore, so after that i cant close that page anymore ... how to solve this and attack ie to that not existing page?
It hasnt got fixed url ... anything that you can recommend?
Is there a method something like "Try attach to ...." because else i get an error if it tries to attack a browser to a link which doesnt exist.
Also is there anyway to check if the link in a links list is still the right one, cuz i also had an exeption few times that it couldnt click on that link because it was empty in the page ...
Or can i check something like link.trytoclick() and if an error and just ignores that link and goes further ???
And the last question after clicking alot of links and opening and closing browser i got an error outofmemoryexception .. how can it be, i've used 'using statement' which always closed browser when it was out of it ...
Thanks in advance for the help.
You can use the href to open the link in the same window of your watin session, after you verify the link you can go back to original page.
Some thing like this:
string href = browser.Link("link_id").GetAttributeValue("href"); //or your link from the collection
browser.GoTo(href);
//Perform you check
browser.Back();
To check if the link exists use:
session.browser.Back();

Categories

Resources