$appiumDriver.find_element(:xpath,‘textfield[@value=“New Passcode”]’)
When I run the above command I get the following error:
An element could not be located on the page using the given search parameters. (Selenium::WebDriver::Error::NoSuchElementError)
I can find the element by providing the direct xpath. Want to check if the above command works or I am doing something wrong?
Try:
$appiumDriver.textfield('New Passcode')
If you want to use xpath, it needs to be valid. textfield is not a valid widget on Android, usually it’d be an EditText. On iOS it’s UIATextField or UIASecureTextField.
1 Like
Thank you for your help.
I got what i was looking for.
how about this in ios?
@driver.find_element(:xpath, ‘//UIAButton[@name=“CREATE A NEW ACCOUNT”]’).click
get Selenium::WebDriver::Error::NoSuchElementError: An element could not be located on the page using the given search parameters.
def get_element_by_xpath(element_path)
begin
$appiumDriver.find_element(:xpath,element_path)
rescue
raise ElementNotFoundException, element_path
end
end
def get_email_with_subject(subject)
if @iosTest
email_subject = $appiumDriver.wait(45){get_element_by_xpath("//UIATableView[1]/UIATableCell[contains(@name,’#{subject}’)]")}
end
sleep(5)
email_subject.click
end
Sometimes when trying to find an element by xpath and performing a click on it, you will need to store it in a variable and then click. Like in the get_email_with_subject method above.
Feel free to let me know if you need more help.
-Diana
Hi Diana,
I am not sure if storing in an element should matter but i also see a sleep in your code and suspect that could really matter. Will try out both and let you know but every time sleep fixes an issue a part of me dies inside. I would really like to know what’s happening then slowing my test down for it to work. again thanks though. will let you know.
I know what you mean with sleep. Its sort of a race condition for now. It finds the element but when click happens it returns Element ID could not be tapped. A sleep sort of fixes it for the time being.
Regarding storing the value, for me it did matter. If the element was not returned both click and send_keys failed for me. iOS and android.