Reputation: 85
I have a class like this:
<div class="qa-share-message ng-isolate-scope ng-valid ta-root
ng-dirty focussed" ng-model="message" text-angular="">
I want to type in this field. i have tried this:
driver.find_elements(:class, "qa-share-message").send_keys("This is a test message")
After running the code it shows error:
undefined method `send_keys' for [#<Selenium::WebDriver::Element:0x65990040 id="33">]:Array
Is it possible to get element by class?
Upvotes: 1
Views: 2834
Reputation: 121000
You obviously got elements by class. Look:
undefined method `send_keys' for [# Selenium::WebDriver::Element:0x65990040 id="33"]:Array
the error above clearly says: the call to find_elements
succeeded and returned an Array
instance, containing Element
s. Everything you now need is to either send_keys
to each found element:
driver.find_elements(:class, "qa-share-message").each do |e|
e.send_keys("This is a test message")
end
or to send it to one of them, e.g. to the very first one:
driver.find_elements(:class, "qa-share-message")
.first
.send_keys("This is a test message")
Upvotes: 1