Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locate elements with Java, XPath and ControlType #60

Closed
Yserz opened this issue Oct 19, 2015 · 31 comments
Closed

Locate elements with Java, XPath and ControlType #60

Yserz opened this issue Oct 19, 2015 · 31 comments

Comments

@Yserz
Copy link

Yserz commented Oct 19, 2015

Hey,

Is there a possibility to locate an element with XPath and the ControlType of an element?
When I try to locate an element with /*[contains(@Name,'WindowName')] and use the method element.getAttribute("ControlType"); I'll get the following output for the attribute:
{ProgrammaticName=ControlType.Window, Id=50032, LocalizedControlType=window}.

How can I check for ControlType.Window in my XPath query? The query
/*[contains(@ControlType,'ControlType.Window') and contains(@Name,'WindowName')] seems not to work.

@skyline-gleb
Copy link
Contributor

Hi,
yes, it does not work, but we fix this soon.
Thanks for message

@Yserz
Copy link
Author

Yserz commented Oct 19, 2015

Great, any workaround for now?

Thx for the fast response :)

@skyline-gleb
Copy link
Contributor

You can use the 'Window' as a control type value, but it will be a dirty hack for this particular case and not work for another control types.

@Yserz
Copy link
Author

Yserz commented Oct 19, 2015

Maybe I'll be better with waiting for the fix. Thx so far!

@skyline-gleb
Copy link
Contributor

Resolved in v1.5.0
This has helped you?

@Yserz
Copy link
Author

Yserz commented Oct 20, 2015

Hm, unfortunately not. Maybe I'm doing something wrong?
I tried the following locators:
/*[contains(@ControlType,'ControlType.Window') and contains(@Name,'WindowName')]
/*[contains(@ControlType,'Window') and contains(@Name,'WindowName')]
/*[contains(@ProgrammaticName,'ControlType.Window') and contains(@Name,'WindowName')]
/*[contains(@ProgrammaticName,'Window') and contains(@Name,'WindowName')]

Without ControlType/ProgrammaticName everything works as expected.

@skyline-gleb
Copy link
Contributor

Attribute ProgrammaticName does not exist and last two locators is wrong.
But /*[contains(@ControlType,'ControlType.Window') and contains(@Name,'WindowName')] work for me, and /*[contains(@ControlType,'Window') and contains(@Name,'WindowName')] too, because 'ControlType.Window' contains 'Window'

@Yserz
Copy link
Author

Yserz commented Oct 21, 2015

Ah, I think I messed something up when replacing the old version. Everything is working as expected. Thx alot :)

@Yserz Yserz closed this as completed Oct 21, 2015
@skyline-gleb
Copy link
Contributor

cool

@ghost
Copy link

ghost commented Apr 23, 2016

Hi, i tried to setup xpath for notepad++ and it did not work for me
driver.findElement(By.xpath("/*[contains(@name,'File')]")).click();
Is it right way of using xpath or a need another?

@JackyVaswani
Copy link

Hi,
I have tried the above written code and it is not for me as well with latest Winium Driver.
Is their any update or workaround for this?

@NickAb
Copy link
Contributor

NickAb commented Dec 29, 2016

@heler12 , driver element usually represents root of your desktop, so searching for /* will search imidiate childrens of desktop only, i.e. open windows, not menu items inside those windows. Most likely you wanted following xpath //*[contains(@Name,'File')], note double slash, which means search in all descendants.

But note that it will traverse a lot of elements in all open windows on your desktop which might make your test run very slow. It is recommended to first locate a window of interest and then use xpath starting from this window. So, you can use your old locator, but you will need to replace driver with mainWindow, where mainWindow is element that correspond to notepad window that you found before.

var window = driver.findElement(By.xpath("/*[contains(@Name,'Notepad++')]"));
window.findElement(By.xpath("//*[contains(@Name,'File') and [contains(@ControlType,'MenuItem')]")).click(); 
// I think it is good idea to limit search scope as much as possible, e.g. by saying it is MenuItem

@venkatags
Copy link

Dear All,
I am stuck. I am trying to automate a desktop app using java and I am able to automate where ever there is Classname and Name but there are cases where the classname and names are duplicated and I have other attributes which bare not duplicate.How does xpath work here.I tried some thing like
WebElement window = driver.findElement(By.xpath("//*[contains(@AutomationId,'27905')]"));

It dosent work.

Help will be really appericiated.

@venkatags
Copy link

I got it worked.Thanks guys.

@ravindrakolhe
Copy link

i am haveing same issue , could pls. let me know..Thanks

@bharadwaj-pendyala
Copy link

@venkatags I am facing the similar problem, may i know how is it resolved?

@rahulbommanaboina
Copy link

What code you have used to retrieve the text ? could you please send .

@kirshru
Copy link

kirshru commented May 17, 2018

I am trying to locate the element(textbox) on the dialog box . There are two elements that has same name "Account". I am interested in the following element (as shown by the spy tool).. I used theXpath. It does not work. What is that I am missing, please

@findby(how = How.XPATH, using = "//*[contains(@ControlType,'ControlType.edit') and contains(@name,'Account')]")

From Inspect.ext tool - spy tool

ControlType: UIA_EditControlTypeId (0xC354)
LocalizedControlType: "edit"
BoundingRectangle: {l:330 t:110 r:552 b:134}
IsEnabled: true

@kirshru
Copy link

kirshru commented May 17, 2018

Tried the following as well -
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[contains(@ControlType,'ControlType.edit') and contains(@name,'Account')]")));


xception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 350 seconds waiting for visibility of element located by By.xpath: //*[contains(@ControlType,'ControlType.edit') and contains(@name,'Account')]
Build info: version: '2.48.2', revision: '41bccdd10cf2c0560f637404c2d96164b67d9d67', time: '2015-10-09 13:08:06'
System info: host: 'v10072463', ip: '10.154.194.55', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_161'
Driver info: org.openqa.selenium.winium.WiniumDriver
Capabilities [{app=I:\FA_Binaries\FirstAssist_2018.5.2.005\Launch_FA_Binaries.bat, args=, innerPort=999

@kirshru
Copy link

kirshru commented May 17, 2018

Please help as soon as possible... thank you

@ankitvaish04
Copy link

@kirshru Could you send the exact screenshots showing all the element properties from inspect tool. There is something wrong in your xpath. The best & the fastest way to traverse through the required element is to traverse from root to node.

@kirshru
Copy link

kirshru commented May 25, 2018 via email

@ganeshsomisetty
Copy link

We are facing similar problem with automation of windows application using c# and winium.

We have two controls with same name and different automationid. But the driver is not recognizing the control with automationid. Is there a way to identify the xpath of required control with UiSpy?

@rateebhatt
Copy link

@ganeshsomisetty driver.findelement(By.id("")) should work could you share your code?

@HaunsTM
Copy link

HaunsTM commented Jun 15, 2018

@rateebhatt, this is probably a stupid question but I need to be sure to understand, does your previous answer mean that driver.findelement(By.id(automationid)) where automationid could be feteched from inspect.exe?

@rateebhatt
Copy link

yes correct

@ganeshsomisetty
Copy link

@rateebhat, we have used the same for identifying the element.

We are using c# and UISpy for identifying the automation id of windows application form elements.

Automationid is different for two elements having same name(on UISpy) on the form. Unable to click the text box element or send keys input is not working.

Any suggestions?

@rateebhatt
Copy link

please try and access the element properties and see if you can do any other action other than click to clarify is element is not found at all OR if the element is found however click could not be performed.

You could use following to make sure element is clickable before performing click action.
WebDriverWait wait= new WebDriverWait (driver,10000);
element=wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("DemoPlan")));
element.click();

@anileapen
Copy link

I don't know how to get a xpath of an element in inspect. Below is the screenshot what I get in Inspect when selecting the element.
image

Could someone help?

@Krishna-QA
Copy link

I got it worked.Thanks guys.

Hi Please let us know how you have resolved the issue ... tried using the following xpath ... winium is not recognizing the same

driver.findElement(By.xpath("//[@classname='Edit']//[contains(@AutomationId,'603')]")).click();

//[@AutomationId='603']//[@classname='Edit']
//[@AutomationId='603']
//
[contains(@AutomationId,'603')]
//[@classname='Edit']//[@AutomationId='603']
//*[@Class="business-name-input]

@Krishna-QA
Copy link

Krishna-QA commented Aug 12, 2020

I was able to solve. Thank you Also any solution to scroll down list box and select Thx Kiran

On Friday, May 25, 2018, ankitvaish04 @.***> wrote: @kirshru https://github.com/kirshru Could you send the exact screenshots showing all the element properties from inspect tool. There is something wrong in your xpath. The best & the fastest way to traverse through the required element is to traverse from root to node. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#60 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AL4wvGj3aElk69Qbt38kcY8he3ceaUxDks5t180kgaJpZM4GRUQZ .

@skyline-gleb @kirshru @venkatags Kindly help on this to resolve
tried using the following xpath ... winium is not recognizing the same

driver.findElement(By.xpath("//[@classname='Edit']//[contains(@AutomationId,'603')]")).click();

//[@AutomationId='603']//[@classname='Edit']
//[@AutomationId='603']
//[contains(@AutomationId,'603')]
//[@classname='Edit']//[@AutomationId='603']
//*[@Class="business-name-input]

WebDriverWait wait= new WebDriverWait (driver,10000);
WebElement element=wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("603")));
element.click();

inspectElement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests