I'm using InternetExplorerDriver with Selenium Webdriver in Java.
I load a URL which simultaneously opens another window which has the login box.
Using the method mentioned here
I could select the required window and also send keys into the focussed box.
popup.getKeyboard().sendKeys("yeuiryuiryweuiryeuiyterui");
However, the following:
popup.findElement(By.id("userName")).sendKeys("user")
is unable to find the element and throws an Element-not-found exception (something similar to this).
Where am I getting it wrong?
I will suggest you to try with xpath
String locator = "//*[#class='Class name of user name text box'and text()='if any']"
you can find the user name through firebug
List<WebElement> element = Driver.driver.findElements(By.xpath(locator));
thn use click functions on web element , do the same on password and then click on login directly using Driver.selenium.click(xpath); and provide the xpath of login button in case id's are not present.
Related
Click button via class because it has no ID . Or via value?
tried className , cssSelector , partialLinkText and LinkText but sadly did not work clicking the save button
System.out.println("Succesful in Saving Product ");
WebElement save = driver.findElement(By.className("bttn-positive save-button"));
save.click();
Should be able to click save button
we can not use the multiple class name in the className locator. So, you can use the XPath locator with the multiple class name as below (//input[#class='bttn-positive save-button'])
Code:
System.out.println("Succesful in Saving Product ");
WebElement save = driver.findElement(By.xpath("//input[#class='bttn-positive save-button']"));
save.click();
You can't pass multiple classnames while using driver.findElement(By.className("bttn-positive save-button")) and doing so you will face Invalid selector: Compound class names not permitted error.
To click() on the green button with text as Save you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.bttn-positive[value^='Save'][type='button']"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[contains(#class, 'bttn-positive') and starts-with(#value, 'Save')][#type='button']"))).click();
Try save.submit();
Submit buttons are used to submit the entire form to the server. We can either use the click () method on the web element like a normal button as we have done above or use the submit () method on any web element in the form or on the submit button itself.
In this case "save.click()" will be work, but some time to save any product on any app like eCommerce or Banking domain it will not working properly & one more important think click () cause a new page to load, this method will attempt to load the page . So better to use "save.submit()" if the current elements is form Or with in the form the this will be submitted. As up ur requirements submit () one is the better option.
I am writing automation test scenario using selenium webdriver in java and cucumber.
Scenario:
2.1 I have two tabs(Parent tab and child tab). I will switch to child tab.
2.2 After switching to child tab and I will refresh a page. After that, I need to click an button in that page.
The problem, Which I am facing is I am unable to click that button element present in that page.
Note:- If I don't refresh a page means, I am able to click that button element in that page.
Even, I tried to get the current url, I am able to get the correct child tab url.
As per my observation, controlling is missing after giving the refresh page via automation.
Can anyone suggest the solution to handle control, after refreshing an web
Sample Code:
#Given("^I choose Segments menu$")
public void I_choose_Segments_menu() throws Exception {
getSegmentsCentralDSL().clickDmpSegmentsButton();
segmentCentralPage.getDmpSegmentGrid();
segmentCentralPage.refreshPage();
Thread.sleep(20000);
ArrayList tabs = new ArrayList(segmentCentralPage.getDriver()
.getWindowHandles());
System.out.println(tabs.size());
segmentCentralPage.getDriver().switchTo()
.window(tabs.get(1).toString());
String currentUrl = segmentCentralPage.getDriver().getCurrentUrl();
System.out.println("currentUrl=" + windowTitle);
}
I am trying to write some UI test cases for an SAP-webUI (web based) application. After login, it shows the dashboard ( Workcenter's ) screen.
Now the problem is, I am able to open the page, enter U/N, Pwd and login through Selenium. After i press the "Login" button the URL changes and the page got redirected/refreshed.
E.g. URL before login : https://a/b/c/d/e/f/g.htm?sap-client=001&sap-sessioncmd=open
E.g. URL after successful Login : https://a/b(bDsdfsdsf1lg==)/c/d/e/f/g.htm
After this im unable to perform any action or press any link in any part of the page. I tried with all the possible attributes ( css, xpath, id ). Webdriver was unable to find any element on the page. It shows the error "No element found" alone.
I am using java with Selenium Web Driver.
Please find the html structure of the webpage below
<html><body><div><div><iframe>#document<html><head></head><frameset><frameset><frame>#document<html><head></head><body><form><div><div><table><tbody><tr><td><div><ul><li><a id=abcdef></a></li></ul></div></td></tr></tbody></table></div></div></form></body></html></frame></frameset></frameset></html></iframe></div></div></body></html>
Actually i want to click a linkmenu "abcd", which is inside iframe and frame as shown in the below HTML code
<html><head></head><body><iframe name=a1><html><head></head><frameset><frameset name=fs1><frame name=f1><html><head></head><body><table><tbody><tr><td><ul><li><a id=abcdef>
I tried the below code as well.
driver.switchTo().frame("a1");
driver.findElement(By.id("abcd")).click();
OR
driver.findElement(By.xpath("//*[#id='abcd']")).click();
After using the above code, still im getting the error "No such element"
Kindly suggest
Regards,
Siva
Do it this way...
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[#name='a1']"))); // switching to iframe
followed by
driver.switchTo().frame("f1"); // switch to frame
and then your desired action...
driver.findElement(By.id("abcd")).click();
This is because of the iframe. You need to switch to it first:
driver.switchTo().frame(0);
driver.findElement(By.id("abcdef")).click();
where 0 is a frame index.
See doc on implicit wait here
I guess you should do a implicit wait until your chosen element is available
modify these code to suit your chosen element:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
I am trying to write a WebDriver test for the following site for learning purposes: http://www.mate1.com
On clicking the login link, I get a form to fill in my email id and password. As far as I understand, the form is shown in an iframe.
To enter the credentials, I tried to identify the number of iframes for that particular page (and found it as 7) and tried switching in to each iframe and search for the email field by XPath and the ID. However, I wasn't successful to find it. So how can this be done?
This is my code:
driver.get("http:www.mate1.com");
driver.findElement(By.xpath("//*[#id='header-container']/div/a")).click();
List <WebElement> frames = driver.findElements(By.tagName("iframe"));
System.out.println("Totalframes -> "+ frames.size());
driver.switchTo().frame(0);
driver.findElement(By.xpath("//[#id='email']")).sendKeys("xxxxxxxxx#rocketmail.com");
This is likely a good situation to use switchTo().frame(WebElement):
driver.switchTo().frame(findElement(By.cssSelector(".iframe-container>iframe")));
The login and password fields are not in an iframe, you can directly use the following code -
driver.findelement(By.id("email").sendKeys("xxxxxxxxx#rocketmail.com");
Try not to switch to any iframe and execute the above line, this will work.
I'm trying to use Selenium (Java) to automate some searches.
When I go to the page and click Inspect Element on the search bar, I see that it has the id searchBox and name q, both of which are potentially useful. Nevertheless, these properties are nowhere to be found in the HTML when I go to View Source.
When I try to use
WebElement search = driver.findElement(By.id("searchBox"));
or
WebElement search = driver.findElement(By.name("q"));
both come back as unable to be found.
How do I proceed with populating the search field then hitting submit (the submit button also is missing in the source page) if I can't find either of these elements?
EDIT:
As requested, here's a more detailed picture of what's wrong:
The URL of the page accessed by WebDriver is http://www.ycharts.com using the line
driver.get("http://www.ycharts.com/login");
If you go to this page with your actual web browser, right click on the search bar and choose Inspect Element, you'll see that its ID is "searchBox" and its name is "q". However, if you go to view the same page's source, you'll see that there's no such element in the HTML. Clearly, this is why WebDriver can't find it.
driver was initiated as follows:
WebDriver driver = new HtmlUnitDriver();
When I try something like
WebElement search = driver.findElement(By.id("searchBox"));`
The exception returned is:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element with ID: searchBox
So, back to the original question: clearly, the element is there, but it's not in the HTML – how do you interact with it?
The problem is being caused by the fact that the search box is added to the html post page load by javascript.
The HTML returned by http://ycharts.com/ does not contain the searchbox, therefore when Selenium thinks the page has finished loading (i.e DOM ready state), there is no search box.
In order to interact with the search box, you need to tell Selenium to wait until the box appears in the DOM.
The easiest way to achieve this is with WebDriverWait;
WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id<locator>));