4
4
from .keywordgroup import KeywordGroup
5
5
from robot .libraries .BuiltIn import BuiltIn
6
6
import ast
7
- import unicodedata
7
+ from unicodedata import normalize
8
8
from selenium .webdriver .remote .webelement import WebElement
9
9
10
10
try :
@@ -55,20 +55,27 @@ def click_text(self, text, exact_match=False):
55
55
By default tries to click first text involves given ``text``, if you would
56
56
like to click exactly matching text, then set ``exact_match`` to `True`.
57
57
58
- If there are multiple use of ``text`` use `locator` with `Get Web Elements` instead.
58
+ If there are multiple use of ``text`` and you do not want first one,
59
+ use `locator` with `Get Web Elements` instead.
59
60
60
61
New in AppiumLibrary 1.4.
61
62
"""
62
- _platform_class_dict = {'ios' : 'name' , 'android' : 'text' }
63
- if exact_match :
64
- _xpath = u'//*[@{}="{}"]' .format (
65
- _platform_class_dict .get (self ._get_platform ()),
66
- text )
67
- else :
68
- _xpath = u'//*[contains(@{},"{}")]' .format (
69
- _platform_class_dict .get (self ._get_platform ()),
70
- text )
71
- self ._element_find (_xpath , True , True ).click ()
63
+ if self ._get_platform () == 'ios' :
64
+ element = self ._element_find (text , True , False )
65
+ if element :
66
+ element .click ()
67
+ else :
68
+ if exact_match :
69
+ _xpath = u'//*[@value="{}" or @label="{}"]' .format (text , text )
70
+ else :
71
+ _xpath = u'//*[contains(@label,"{}") or contains(@value, "{}")]' .format (text , text )
72
+ self ._element_find (_xpath , True , True ).click ()
73
+ elif self ._get_platform () == 'android' :
74
+ if exact_match :
75
+ _xpath = u'//*[@{}="{}"]' .format ('text' , text )
76
+ else :
77
+ _xpath = u'//*[contains(@{},"{}")]' .format ('text' , text )
78
+ self ._element_find (_xpath , True , True ).click ()
72
79
73
80
def input_text (self , locator , text ):
74
81
"""Types the given `text` into text field identified by `locator`.
@@ -548,7 +555,12 @@ def _element_input_value_by_locator(self, locator, text):
548
555
def _element_find (self , locator , first_only , required , tag = None ):
549
556
application = self ._current_application ()
550
557
if isstr (locator ):
551
- elements = self ._element_finder .find (application , locator , tag )
558
+ # Normalize any unicode as explained here, http://appium.io/slate/en/master/?javascript#multi-lingual-support
559
+ if self ._get_platform () == 'ios' :
560
+ _locator = normalize ('NFD' , locator )
561
+ else :
562
+ _locator = locator
563
+ elements = self ._element_finder .find (application , _locator , tag )
552
564
if required and len (elements ) == 0 :
553
565
raise ValueError ("Element locator '" + locator + "' did not match any elements." )
554
566
if first_only :
@@ -567,10 +579,8 @@ def _get_text(self, locator):
567
579
return None
568
580
569
581
def _is_text_present (self , text ):
570
- text_norm = unicodedata .normalize (
571
- 'NFD' , text ).encode ('ascii' , 'ignore' )
572
- source_norm = unicodedata .normalize (
573
- 'NFD' , self .get_source ()).encode ('ascii' , 'ignore' )
582
+ text_norm = normalize ('NFD' , text ).encode ('ascii' , 'ignore' )
583
+ source_norm = normalize ('NFD' , self .get_source ()).encode ('ascii' , 'ignore' )
574
584
return text_norm in source_norm
575
585
576
586
def _is_element_present (self , locator ):
0 commit comments