Getting the Value of a Textfield

Does anyone know of a way to get the value of a textfield? I need to validate the text that goes from one iOS screen to another.

I am using the Ruby framework.

Thanks,
Patrick

java like:
driver.findElement(MobileBy.Id("someId")).getAttribute("value")
or
driver.findElement(MobileBy.Id("someId")).getText()

2 Likes

@skycamefalling, If you have the element, you can use the text method:
element.text

Thanks but I am getting an error.

Code: puts shippingaddress.streetaddress1_field.text

Error: Failure/Error: puts shippingaddress.streetaddress1_field.text
ArgumentError:
wrong number of arguments (0 for 1)

That’s odd. You say you are using Ruby. Can you provide the code showing how you obtained shippingaddress.streetaddress1_field?

def streetaddress1_field
element(:textfield, “Street Address Line 1”)
end

This is in my page object. Is there something I need to ‘require’ for .text to work?

Does this element method find the element by some type that recognizes :textfield? I can’t answer that question from looking at your code. Print out the class and available methods and you will likely have the answer

I will give that a shot - thanks!

im currently having the same problem, is there any solution to this?

Is there a method, where i can check if the text field is filled with a text? Like i proceed to the next screen only when the OTP is filled. I am giving a sleep command which I dont want to, dont like hardcoding.

So, is there something, i can assert in the text field, whether its filled with numbers or not? like find_element().size > 0?

find_element.text.size > 0

If your text field is prepopulated with default text, you’ll need to check that condition as well