i need to select the first element from an autocomplete search box ,
when autocomplete shows its hover other element,so other element not clickable by protractor ,
solution
element.all(by.css('[ng-model="address"]')).get(0) is not work for me but work in another computer ,
same script work in another computer ,
i checked protractor version , selenium version
i also try element.all(by.css('[ng-model="address"]')).first() ;
its also not work for me ,
do you have any idea how cant i get first element ?.
thanks
you can send enter key
protractor.Key.ENTER
yourelement.sendKeys('your text to send ', protractor.Key.ENTER);
The Autocomplete List is only visible if a curser is over the element.
this.selectFirstElement = function(element){
browser.sleep(3500);
browser.driver.actions().mouseMove(element);
element.sendKeys(protractor.Key.ARROW_DOWN);
element.sendKeys(protractor.Key.TAB);
};
Try adding a short delay (say 500ms) and then do click. Sometimes the rendering of autocomplete misses the first item.
Related
On the application I work , after tabbing out of every field, there is an AJAX call , some blue spinner at the bottom . If we enter text in a field while the spinner is present , field doesnt retain its value , is it possible to to write some while loop or something ...
which checks whether value has been set properly or not otherwise re enter it
Thanks
I have tried
Send Keys
Javascript Executor
But they dont work
Try this:
if(element.getAttribute("value").isEmpty() == true) {
((JavascriptExecutor) driver).executeScript("arguments[0].value='someInputText';", element);
}
How do I create a Xpath of any element in web page when it is changes each page load or refresh using selenium
If there is 1 submit button, you can find element by checking input type submit
//input[#type='submit']
If there are more and you know it place in page for example 2. Search by child number as:
( //input[#type='submit']) [2]
You can try this method it works fine.
Here is my xpath,
//*[#id="CaseTypes_39aa6635-cd44-4104-a9f7-e33c3f96e2ab__Amount"]
Here is my code:
[FindsBy(How = How.XPath, Using = "//*[starts-with(#id, 'CaseTypes_') and substring(#id, string-length(#id) - string-length('__Amount') +1) = '__Amount']")]
I hope it helps!!
i am trying to Automate flipkart website in which i am trying to change address but "add new adress" is not getting clicked i have attached the snapshot
my code is like driver.findElement(By.xpath("//*[#id='ng-app']/div/div[2]/ul/li[2]/div/div[2]/div[2]/div[2]/a/span")).click();
please give the appropriate help
I doesn't look that you are clicking active element, the xpath is //*[#id='ng-app']/div/div[2]/ul/li[2]/div/div[2]/div[2]/div[2]/a/span not correct it clicks on some span.
Use Firepath https://addons.mozilla.org/en-US/firefox/addon/firepath/ to get the xpath.
To ensure that button is clickable Use isDisplayed() and isEnabled() method before clicking on "Add New Address" button, this method return boolean value.
driver.findElement(By.xpath("//*[#id='ng-app']/div/div[2]/ul/li[2]/div/div[2]/div[2]/div[2]/a/span")).isDisplayed();
driver.findElement(By.xpath("//*[#id='ng-app']/div/div[2]/ul/li[2]/div/div[2]/div[2]/div[2]/a/span")).isEnabled();
Also you can verify that element is exist on page or not using below code
if(driver.findElements(byVal).size()!=0){
// Element is present.
}
hope it may helpful to identify cause of issue, why its not clickable.
First and foremost, Use a customized Xpath instead of the one you are using which is extracted directly from the browser. If no customized Xpath can be constructed then try a customized Css or any other locator if possible.
Try to go through the following attempts in order (I hope you can grasp why this is):
1- If .click() still doesn’t work, then keep on changing the values of the attributes you are using to construct your customized xpath, cssSelector, or locator.
2- Use the Actions class.
3- Use JavaScript executioner
4- instead of click(), try using any of: .sendKeys(“\n”). Or .sendKeys(keys.ENTER) or .sendKeys(keys.RETURN)
I click on the drop down list button.Then it is coming like the mentioned picture.
so I have to click on Item1. after that I have to select Xyz. so which way should I follow?
You can do it in many ways.
By using getFirstSelectedOption(), you can select your first element, and by using selectByVisibleText("Xyz") selenium will click on Xyz, but the thing is your DOM must contain select attribute for dropdown. There are many other ways to create dropdown option in HTML.
Select dropdown = new Select(driver.findElement(By.xpath("//img[#id='ext-gen7']")));
dropdown.getFirstSelectedOption();
dropdown.selectByVisibleText("Xyz");
Now, if your DOM is not using select for creating dropdown, you can also use the .click() method directly. Find the elements and click on that location directly using .click(). This will work many times.
List<WebElement> examples = driver.findElements(By.xpath("YOUR XPATH"));
for (WebElement option: examples)
{
if(option.getText().contains("Item2") )
option.click();
else{
syso("I do not want to click")
}
}
Make sure the above Xpath should return all your values of dropdown.
I'm using Selenium Webdriver to test a web page.
The web page http://www.leaseplan.nl/contact/index.asp has two buttons, one button with button text 'Zoeken' and one with button text 'Verstuur'. I want to click on the button with button text 'Verstuur' either by using XPath or CssSelector with the following code:
driver.FindElement(By.XPath("/html/body/div[3]/div[2]/div[2]/form/fieldset/a/span")).Click();
driver.FindElement(By.CssSelector("fieldset.contact_form > a.button > span.button_center")).Click();
But using the either one of the above lines of code, on the button with text 'Zoeken' is clicked on instead.
This button has quite a similar CssSelector and XPath:
fieldset.header_search a.button span.button_center
/html/body/div[3]/div/form/fieldset/a/span[2]
Does anybody know how to solve this?
Try this out with the cssSelector and tell me if it's work.
For "verstuur" :
By.cssSelector("div.content form a.button")
Solution :
Ok, i've found your problem. Your xpath is good but now, your action on the click submit the first form, so the form with "Zoeken".
onclick="document.forms[0].submit();" // submit the 1st form, the bad one !
Try this :
onclick="document.forms["form"].submit();" // submit the 2nd form, the good one !
//or
onclick="document.forms[1].submit();"
proof : Jsfiddle
xpath for ZOEKEN /html/body/div[3]/div/form/fieldset/a/span[2]
xpath for VERSTUUR /html/body/div[3]/div[2]/div[2]/form/fieldset/a/span[2]
Try this:
driver.FindElement(By.XPath("//span[text()='Verstuur']")).click();
Edit:
I think you want to learn Selenium that's why you are using 3rd party websites. If you really want to learn Selenium find some opensource applications to automate. Here is a good application to automate -
http://sourceforge.net/projects/sugarcrm/files/1%20-%20SugarCRM%206.5.X/FastStack/
Download the latest version and install.
Find more info about the website and selenium stuff here. It's so good..
http://selftechy.com/2011/02/05/introduction-to-selenium-web-application-test-automation-tool
Zoeken: driver.findElement(By.xpath("//div[1]/form/fieldset/a/span[2]")).click();
Verstuur : driver.findElement(By.xpath("//div[2]/form/fieldset/a/span[2]")).click();
Using xpath is easy but slow.