I'm trying to automate one of my hybrid app using Appium. I'm getting an issue while clicking on the Login button. The error message I'm getting is:
org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (116, 329). Other element would receive the click: <button class="button button-medium button-custom-login " ng-click="login()">...</button>
And I just want to click on the same element i.e. the one mentioned here with attribute ng-click="login().
I've changed the context already to WebView and tried with changing the attribute to Native as well but nothing seems to be working.
The code which I've used to identify this element is below:
List<WebElement> labels = driver.findElementsByTagName("button");
I iterated through all the elements and found that I need to click on number 20 element.
Any help on this would be great. Thanks!
You should try using Actions class as below :-
WebElement element = driver.findEle....
Actions action = new Actions(driver);
action.moveToElement(element).click().perform();
If you have found that you need to click on number 20 element in the list, you could go this way:
int pos = 20;
List labels = driver.findElementsByTagName("button");
labels.get(pos-1).click();
Related
I have tried a different method to input elements like
Here is xpath I used
By NameOfTheProperty=By.xpath("//fieldset/div/input[#name='name']");
By NameOfTheProperty=By.xpath("//div/input[#name='name']");
By NameOfTheProperty=By.xpath("//input[#name='name']");
Tried with Selenium Builder
WebElement element=driver.findElement(by);
Actions builder = new Actions(driver);
Action mouseOverHome = builder
.moveToElement(element)
.click().sendKeys(text).build();
mouseOverHome.perform();
Tried with
WebElement element=driver.findElement(by);
element.sendKeys(text);
None of the methods is working..I can not able to input text inside the field and It shows
Element not interactable
Here is the site
I hope someone help me to find out the solution..
Please check in the dev tools (Google chrome) if we have unique entry in HTML DOM or not.
Steps to check:
Press F12 in Chrome -> go to element section -> do a CTRL + F -> then paste the xpath and see, if your desired element is getting highlighted with 1/1 matching node.
xpath you should checks is :
//input[#name='name']
if it is unique, then you can use Javascript executor :
WebElement password_input = driver.findElemenet(By.xpath("//input[#name='name']"));
((JavascriptExecutor) driver).executeScript("arguments[0].setAttribute('value', 'password_should_be_written_here')", password_input)
personally I would use id's if the element has one.
"//*[#id='__BVID__104']"
Make sure you are waiting for the element to be ready.
WebDriverWait wait = new WebDriverWait();
wait.until(ExpectedConditions.elementToBeClickable(element));
If it then times out on wait.until(... then I've found that sometimes an element must first be clicked for it to be exposed.
If this is the case. You will have to inspect the element before it is clicked. Find it's xpath, and see if it changes when it is clicked. If so then create a webElement for that element and have Selenium first click it, before clicking the actual field/element.
I am using firebug for finding xpath, this is the error that is displayed in the error console.
no such element: Unable to locate
element:{"method":"xpath","selector":".//*[#id='select2-contact_id-result-v0w5-258']"}
driver.findElement(By.xpath(".//*[#id='select2-contact_id-result-v0w5-258']")).click();
html is as follow
id="select2-contact_id-result-v0w5-258" class="select2-results__option select2-results__option--highlighted" role="treeitem" aria-selected="false">Single contact
There could be following reason for it :-
May be your id is dynamically generated, so you need to try with different locator to create By object as below
By by = By.className("select2-results__option select2-results__option--highlighted");
or
By by = By.cssSelector(".select2-results__option select2-results__option--highlighted");
or
By by = By.xpath("//*[contains(., 'Single contact')]");
or if id is not dynamically generated
By by = By.id("select2-contact_id-result-v0w5-258");
May be your element is inside a frame or iframe, If it is then you need to switch that frame or iframe before finding element as below :-
driver.switchTo().frame("frame id or name or index");
May be element is not being fully loaded on the page due to slow internet, so you need to implement WebDriverWait to wait until element is visible and clickable as below :-
WebDriverWait wait = new WebDriverWait (driver, 10);
WebElement el = wait.until(ExpectedConditions.elementToBeClickable(by)); //use anyone of the above by object
Now after successfully getting element you need to perform click as below :-
el.click();
Note :- if your element is actually a dropdown with select tag, then you need to create Select() object to work with dropdown as below :-
Select sel = new Select(el);
//now perform step to select an option by visible text from dropdown
sel.selectByVisibleText("your visible option text");
or
sel.selectByIndex("your option index");
or
sel.selectByValue("your option value");
Hope it helps you..:)
I tried to locate a link "Sign in" located in the window which appeared when mouse move on to "Mail" link on Yahoo. I can get the xpath using firebug. but when i used it in the script, it doesn't work.
HTML snippet :
<a id="yui_3_18_0_4_1456816269995_943" class="C($menuLink) Fw(b) Td(n)"
data-ylk="t3:usr;elm:btn;elmt:lgn;" data-action-outcome="lgn"
href="login.yahoo.com/config/…; data-rapid_p="23">Sign in</a>
I tried this in my code within main method,
WebElement element = driver.findElement(By.id("uh-mail-link"));
Actions action = new Actions(driver);
action.moveToElement(element).build().perform();
driver.findElement(By.id("yui_3_18_0_4_1456804882382_929")).click();
id selecter;
driver.findElement(By.id("yui_3_18_0_4_1456804882382_929")).click();
It prompts this error;
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"yui_3_18_0_4_1456804882382_929"}
Command duration or timeout: 17 milliseconds
Can we locate it using id of appeared window ".//*[#id='yui_3_18_0_4_1456804882382_919']" and linkText "Sign in", or are there any other methods to locate it in the script.
You're supposed to pass just id to By.id(), not an XPath expression :
driver.findElement(By.id("yui_3_18_0_4_1456804882382_929")).click();
or use By.xpath() instead of By.id() if you need to find the element by XPath expression, for example, by using combination of id and link text to locate the target element.
UPDATE :
You can filter element by its text content and id like so :
//a[#id='yui_3_18_0_4_1456816269995_943' and .='Sign in']
Have you tried putting 2 functions ? 1 for mouse over and 1 for actual clicking ?
I have a sample in Java if you need.
public void mouseOver(String xPath){
Actions action = new Actions(driver);
WebElement element = driver.findElement(By.xpath(xPath));
action.moveToElement(element).moveToElement(driver.findElement(By.xpath(xPath))).click().build().perform();
Thread.sleep(500); //too actualy see if is it performs
}
public void click(String xpath) {
driver.findElement(By.xpath(xpath)).click();
}
You can change the searching method from xpath to id, or whatever you need.
Be aware that the mouseOver function has a different xpath/id to send from the click method because , you mouseOver on first button, and you click the other link that will apear after.
Hope it helps.
Is there any way to scroll page to current webElement using selenium for Java?
I would like to click on element but when the element is down or up it clicks on another place - so I want to scroll page to current element.
I searched but havent found any solution.
Any help - Advance Thanks !
You need look up the id and fire click event on that id.
I want to click on next button on my page whose id="nextButton"
In the page object here is how i declared. That way you dont need worry about where the position is
Eg:
#FindBy(how = How.ID, using = "nextButton")
private WebElement next;
More info at
http://reddymails.blogspot.com/2011/09/selenium-2-or-webdriver-for-automation.html
I've been working at this for some time now. I'm using Selenium and WebDriver version 2.33 (with all browsers). I'm using Java, which should be arbitrary. What I'm doing is simply find an element and hover over it, which I have done in earlier code. But for some reason, I can't get this one to work. I'm trying to get an element with this xpath, obtained by right-clicking the element in the HTML in Chrome and clicking "copy xpath":
//*[#id="highcharts-10"]/svg/g[7]/g/rect[1]
This is how I'm trying to get the element (due to "highcharts-10" dynamically changing):
//*[starts-with(#id, 'highcharts')]/svg/g[7]/g/rect[" + barOption + "]
barOption is inputting correctly (there are a bunch of bars that I'm trying to go through)
Here is my Java code:
WebDriverWait wait = new WebDriverWait(getWebDriver(), 5);
WebElement element;
WebDriver driver = getWebDriver();
By by = By.xpath("//*[starts-with(#id, 'highcharts')]/svg/g[7]/g/rect[" + barOption + "]");
Actions action = new Actions(driver);
WebElement elem = wait.until(ExpectedConditions.visibilityOfElementLocated(by));
action.moveToElement(elem);
action.perform();
What am I doing incorrect here? I've tried using switchTo() statements, but there are no iframes that I can correctly switch to. Here is a picture the HTML because I can't get my hands on the actual text:
UPDATED HTML LINK:
http://i1250.photobucket.com/albums/hh527/dr4g1116/Capture_zps6e2bc1b9.png
Anyone have any suggestions for me? Please let me know what I'm doing wrong!
Thanks!!
Try as CSS Selectors :
By by = By.css('div[id^="highcharts"] g[class^="highcharts"] > g > rec')
g.class_name I used,as that <g> tags class name is not visible. Replace that class name with the proper class name.
I just wanted to give a slight update on this. It seems selenium can't see past the SVG tags, so with that being said, I need to find a method to see around them...I will report back if I'm able to find out how.
Thanks all!
From your discussion with Amey i deduced that you have only one highchart. so try directly searching for element "highcharts-tracker" using classname i.e By.ClassName("highcharts-tracker") and then hover on this element itself. This would exactly do what you want to achieve.
Sorry just seeing your comment on my earlier answer.
You can get the values for each bar in barchart by following way:
var barValues = new List<string>();
var actions = new Actions(webDriver); //webDriver is instance of selenium WebDriver.
var chartSeriesGroup = webDriver.FindElement(By.ClassName("highcharts-series-group"));
var chartSeries = chartSeriesGroup.FindElement(By.ClassName("highcharts-series"));
var rectTags = chartSeries.FindElements(By.TagName("rect")); //To get all bars in barchart.
foreach (var rect in rectTags)
{
actions.MoveToElement(rect).Perform(); //Hover mouse on bar.
var trendMarkers = webDriver.FindElement(By.ClassName("highcharts-tooltip"));
barValues.Add(trendMarkers.Text); //Storing tooltip value of bar for later use.
}
I am using same method in my current project for getting values of bars in bar chart. Hope this will help you.
Note : If tooltip for bar shows other information e.g.name etc along with value then you need to write logic for extracting the value part from the complete information stored in barValues.