그래서 "버튼을 누르기위한 일반"I "*" "Gherkin 문을 사용합니다. 내 문제는 텍스트가 응용 프로그램 전체에 표준화되어 있지 않다는 것입니다.Ruby/Appium : 텍스트 속성을 통해 find_elements 배열에서 요소를 선택하는 방법
find_elements를 사용하여 모든 버튼 요소의 배열을 구성하고 내 작은 오이 입력 (예 : '예'버튼 누르기)에서 텍스트를 가져 와서 .casecmp 메소드를 사용하여 무시합니다. find_elements 배열에서 버튼 텍스트를 대문자로 변환하고 텍스트 속성과 내 작은 오이 입력을 비교합니다. 나는 이러한 오류가 내 경우에는 무슨 뜻인지 전혀 모르겠어요하지만 '
And I press the "YES" button # features/step_definitions_android/common_steps.rb:107
no implicit conversion of Selenium::WebDriver::Element into Integer (TypeError)
./features/step_definitions_android/common_steps.rb:113:in `[]'
./features/step_definitions_android/common_steps.rb:113:in `block (2 levels) in <top (required)>'
./features/step_definitions_android/common_steps.rb:111:in `each'
./features/step_definitions_android/common_steps.rb:111:in `/^I press the "([^"]*)" button$/'
features/FAB.feature:18:in `And I press the "YES" button'
:
Then (/^I press the "([^"]*)" button$/) do |button_text|
#assign gherkin input to variable
@button_text = button_text
#create find_elements array for all Buttons
button_array = find_elements(xpath: "//android.widget.Button")
#create for loop that will compare each element's text with @button_text
button_array.each do |index|
#Attempting to reference text attribute of array at index and compare @button_text with case insensitive comparison
matching_button = button_array[index].text.casecmp("#{@button_text}")
if matching_button = 0 #this means it's a match
button_array[index].click()
else
end
end
end
나는 다음과 같은 오류를 얻을 순간 :
다음은 코드에서 내 시도이다 내 연구를 계속하고있어. 누구든지 내가 잘못하고있는 것에 대해 통찰력을 공유 할 수 있다면 크게 감사하겠습니다.
appium이 요소를 배열에 저장하는 방법에 대한 문서가 있습니까? 요소의 텍스트 속성을 변수 또는 다른 값과 비교할 수 있습니까? 당신이 저에게 줄 수있는 도움에 대해 감사드립니다.
감사합니다. 제 경우에는 다음과 같이 케이스 문제를 해결하기 위해 caseless 비교를 추가해야했습니다 : button_array.each do | btn | btn.text.casecmp ("# {button_text}") == 0 끝 그렇지 않으면 내게 필요한 것이 무엇인지, 고마워! –
다행스럽게도이 방법이 도움이 될 수 있습니다. 대소 문자를 모두 대문자로 변환하여 비교할 수있는 경우 다른 옵션을 사용하면 다른 옵션을 사용할 수 있습니다. btn.text.downcase == button_text.downcase 도와 줄 수있어서 기뻐!! –