Not able to click an element present under LinearLayout in the Appium - java

I want to click the country on Country code page while registering.
However, I have tried every findbyElement method i can to click the element, but it always result in
No Such Element Error.
Can anybody please help me in that.
PS: I have used xpath, ID and List. But its not working, If you have any idea from the tried methods, please do share as I am new to Appium and can be wrong.
Thanks
screenshot
Dumpfile screenshot
DumpfileforUIautomator

You can try by using xpath or name
driver.findElement(By.xpath("//android.widget.TextView[#text='India']")).click();
or
driver.findElement(By.Name("India")).click();
or
driver.findElement(new By.ByName("India")).click();
or
driver.findElement(By.xpath("//android.widget.TextView[#index='2']")).click();

The issue is that You are locating wrong control, You should be targeting radio-button/check-box control, not label next to it.
Try locating that control, not label.
driver.findElement(By.className("CheckBox Locator")).click();
try one of this solutions:
List<MobileElements> listElement = driver.findElements(By.id("com.bondevalue.BondEvalue:id/country_rb"))
System.out.println("Size: " + listElement.size());
and then check out if this is returning any result. If it does than elements are found.
Than You have to find parent layout com.bondevalue.BondEvalue:id/listlayout and find every in list, and find child elements (checkboxes) like shown, and when found desired element by text (com.bondevalue.BondEvalue:id/labelk) then click on check box (com.bondevalue.BondEvalue:id/country_rb).
Hope this helps...

Based on the screenshot of the checkbox control, it looks like the resource id is -not- unique, which is probably why the element is designated as NAF (not accessible friendly).
Therefore, I would instead access the textview immediately following it, then use preceding-sibling to access the desired checkbox:
driver.findElement(By.xpath("//android.widget.TextView[#text='+91']/preceding-sibling::android.widget.CheckBox"))

Related

Selenium returning text from path not specified in xpath statement

I have text located in these two locations:
The elements I want the text from:
//*[#id="RoleSetUpNewForm"]/div/table/tbody/tr[1]/td[2]/table[2]/tbody/tr/td/div[1]/table[3]/tbody/tr[2]/td/table[1]/tbody/tr/td[2]/table[1]/tbody/tr/td/label
The elements that I do not want the text from:
//*[#id="home"]/div[16]/form/div/table/tbody/tr[1]/td[1]/table/tbody/tr[18]/td[3]/div/a
This xpath statement when executed in Selenium keeps giving me both the elements I want, AND the elements I do not want:
driver.findElements(By.xpath("//td[#class='level3TD']/label"));
Clearly the xpath above does not reference the location that I do not want the text from, but I am getting the text elements from it returned..
I am just baffled. Any ideas? Is there something I need to do with my selenium xpath query to stop the text from the path ending in /div/a from coming back?
There is no need to manually write XPath's.
Open the dev console by pressing F12 (assuming you are on a Windows machine).
Now find the node that you want, right click on it and click "Copy". Now you can copy the relative XPath, Full XPath, JS Path or Selector. In your case you look like you want the Full XPath.
This can be done on all machines, in all browsers.
I figured this out, there were duplicate label text on the page that made me think the xpath was pulling from the wrong location. Lets close this.

Accessing an element with unknown id but known path

I am working on a testing program that operates with very little information. In this particular case, my program doesn't know the ID of elements in the page before it runs, because the Javascript on the page dynamically assigns those at run time. The only constants I have is the structure and the text I'm looking for. I'm including a screenshot of one example of the DOM being generated. In this case I know that I want to access the button with text apply that is displayed next to the label with the text "To Location:" Is there a way to use xpath manipulate their relationship and ensure that I'm accessing the right element. I can't just access the apply button because there are 6 apply buttons on the page with dynamically generated IDs. The label's next to them are different so I'm trying to use that and manipulate the path's from there. Help?
This is possible. If you provide the entire html code I could provide a better xpath. But for what you pasted, here's a simple one that might work:
//td[div//label[text()='To Location:']]/following-sibling::td[1]//button[text()='Apply']
There's a slightly longer winded way but thats generating a list of elements by class and clicking the one with the right text
`var elements = driver.FindElements(By.Class("text-pb"));
foreach(var element in elements)
{
if(element.Text.Equals("Searched Text"))
{
element.click();
}
}`
that might work thats if you want to click the button.
i use these sort of things on the pages works site generates so it should do what your after.

Selenium - Check if an element is under another one

I'm using Selenium to do Java test.
I know that i can check if an element is enable or displayed with this :
isDisplayed
isEnabled
Is it possible to check if an element is not visible, in the case that this element is under another ? For example, if a div is under another one.
With that i want to check GUI element. For example if a button move under element, etc ...
Any ideas ?
thanks for helping _
selenium.isElementPresent() or selenium.isVisible()
those may help you.
isElementPresent() - This method basically tests if the element we are looking for is present somewhere on the page.
isVisible() - looks for display: none style tag - this might throw a null pointer if we aren't careful...thus to see if an element is visible first check if the element is present using isElementPresent() method. Then try checking if the element is visible!
I think constructing your locator like this might do it.
By TOP = By.xpath(".//div");
By UNDER = By.xpath("..//..//div");
By elementUNDERtheTOP = new ByChained(TOP, UNDER);
This is the equivilant of:
driver.findElement(TOP).findElement(UNDER);
This is possible to do with XPath but I don't think you could do this with a CSS locator because a CSS locator would not be able to traverse up the DOM tree to parent elements.
Lets say you want to click an element, but that element is "behind"/"below" (aka 'obstructed' by anlother element), Selenium will actually throw a ElementClickIntercepted exception. As part of the exception message, it also returns which point you tried to click and which other element (tag, class) did intercept the click. By simply attemping to click an element and specifically catching this type of exception, you get the information you're looking for, if you catch such an exception => element not clickable (at the given coordinates - in most cases the default click point (or if you use actions: the offset you define)), if no exception => element is clickable.
The solution for Python is here.
It should be easy to convert it to Java.

Unable to click on link given in dropdown. Able to get link text and also link is highlighted when i do click();

I have used findElements to get all elements in drop down.
List<WebElement> list = driver.findElements(By.xpath("//*#id='flyout']/div[1]/ul/li"));
In a for loop, I am getting the name of the link. Now I want to click on the link. When I do list.get(i).click();, the corresponding element is highlighted but click is not happened. also no error was thrown.
I'm using Firefox.
Note: I have used findElements as drop down is not given in select value in HTML.
As you mentioned that the drop down has a "link". I think the list of elements that you are iterating through are just li elements, make sure there is an < a href .. > element within the li element. You need to click on the < a > and not < li >.
I hope this helps.
Also, if you already know which option in the list you want to click why are you storing the complete list and then iterating through it? Just find the link with the desired text and click it!
driver.findelement(by.linktext("link text")).click()
I would assume your xpath does not really return the clickable element.
If dropdown items are links, then perhaps need to provide locator that leads to the hyperlink.

How to get Selenium Webdriver to recognize elements with changing id numbers within it

how do I get the xpath or css or ANYthing to click this ok button??? Problem is these ids and other attributes have tags that are changed every time a user goes to this particular page
--ea3b2e21-3847-47de-860c-3596695fbb35-- so i don't know what to do
Ok
All you can do here is try and find some part of the element that does not change. If you can add some sample html it would help.
Have you read the
docs for dynamic elements?

Categories

Resources