1

enter image description hereIn mobile app(android), we have a Date control of class android.widget.spinner type. After selecting the value from this control, I tried to get the value using selenium code

driver.findElement(By.xpath("//*[@resource-id='dttDate']"))).getText();

But the above code giving blank value.

Can some one help how to get a value from android.widget.spinner control.

SeJaPy
  • 284
  • 1
  • 6
  • 18
  • Please share block of HTML Code – Ishita Shah Jun 26 '18 at 07:26
  • duplicate of https://stackoverflow.com/questions/1947933/how-to-get-spinner-value – Prany Jun 26 '18 at 08:01
  • @IshitaShah, I've added code screenshot. Please have a look. – SeJaPy Jun 26 '18 at 08:48
  • If you see Text property in your screenshot, it is not containing any text for what you wants to retrieve. Just above of class what you have marked in Selected Element section – Ishita Shah Jun 26 '18 at 08:56
  • @IshitaShah, Thank you. Yes our android development team saying for spinner they wont show any value for text attribute. Hence I posted question if there is any alternate to get this value. – SeJaPy Jun 26 '18 at 08:59
  • We need that Text to be available in DOM, If it is not present in DOM, We can't retrieve it. – Ishita Shah Jun 26 '18 at 09:01
  • Ask your development team if they have a "Value" attribute, in in lieu of that, how do they internally access the value of the spin control? – Bill Hileman Jun 26 '18 at 13:27

1 Answers1

0

In The screen shot what you have mentioned, you can see in the attribute list text value is empty, since text attribute value is empty you cannot use getText() method. Select the field properly so that text attribute field is visible with text and use the getText() method. Click on date and select date properly to get the text attribute value.

field with text attribute

field without text attribute

Click on the date instead of whole field and check if the text attribute value is present, if text is present, you can use getText() Method.

vijay j
  • 1
  • 1