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();
Related
I have got a problem with Selenium code to find a button which has only "Value" and "type", in inspection it looks like this:
<input type="sumbit" value="login" />
Image of inspection
I tried twice but neither line worked for me.
The lines:
1st solution:
driver.FindElement(By.XPath("//button[contains(text(),'Login')]")).Click();
2nd solution:
driver.FindElement(By.ClassName("submit")).Click();
Image with ERROR MESSAGE (second line error)
Can anybody help me, or at least point out what am I missing, because its getting pretty frustrating to find a solution for such common thing, I practiced this on tutorial pages and buttons were never a problem.
Please. (Sorry for my English)
P.s.: I checked the "similar questions and I haven't found the solution.
P.s.s: Guys, there is another one which I didnt try yet but I have 3 different lines of code, do you think one of them will work:
There is drop-down list and I want to select the last thing in the list...
driver.FindElement(By.XPath("//*[contains(., 'Process Data >>')]"));
driver.FindElement(By.Id("pdatasub")).Click();
driver.FindElement(By.XPath("//div[text()='Process Data >>']")).Click();
Inspection of the Drop-down list
Code for the opening of the last "button" in the drop-down list:
driver.FindElement(By.XPath("//div[text()='Final Values']")).Click();
enter link description here
Thanks guys for help !
You are using the wrong locator :
try this instead :
driver.FindElement(By.XPath("//input[#type='submit' and #value='Login']")).Click();
or
With ExplicitWaits
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[#type='submit' and #value='Login']"))).Click();
Your locator is wrong.
You can use this:
driver.FindElement(By.XPath("//button[#type='submit']")).Click();
or
driver.FindElement(By.XPath("//button[#value='login']")).Click();
or
driver.FindElement(By.XPath("//button[#value='login' and #type='submit']")).Click();
CSS Selector can be used as well similarly.
Also there are several possible issues:
You should add a wait before accessing that element. Otherwise you are trying to find an element while page is still not loaded. Expected conditions are the preferred way to do this with.
The element can be inside an iframe. If so you have to switch to that iframe in order to access elements inside it.
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 :)
I'm trying to select a value from a dropdown list but I'm getting an ElementNotVisibleException error.
new SelectElement(driver.FindElement(By.CssSelector(select.selectText[name=ADT]))).SelectByValue("2");
And you can see the website that I try to select from dropdown list is
Css of the website
I believe there something to do with jQuery as well but I'm not sure..
Thanks.
You can try something with JavaScript. For example, if you have a hidden button, you can click that button in this way:
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", driver.FindElement(By.Id("loginLink")));
See if you can apply the same thing for your dropdown element.
Hope it helps.
Don't you just miss a quotation mark there?
css=selector.class[attribute='value']
In your case:
select.selectText[name='ADT']
or ""
Please try this :
new Select(driver.FindElement(By.CssSelector(select.selectText[name='ADT']))).SelectByValue("2");
You'll need to wait until the element is visible using an explicit wait.
wait.until(ExpectedConditions.visibilityOfElement(By.cssSelector("select.selectText[name=ADT]")
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?
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();