EDIT: upon further testing, it seems like the issue is site-specific and should theoretically work just fine.
Textarea values which should be on multiple lines are being submitted all on one line.
textarea_values = "value1\nvalue2"
form = page.form_with(:id => 'form_id_here')
form['my_textarea'] = textarea_values
submit = form.button_with(:value => 'Submit')
form.click_button(submit)
The value being submitted is value1\nvalue2
instead of being on multiple lines as intended.
Is there another way to add form values that I can try?
Have you really tried the code you posted here?
Well I have in a website that has internal messaging system, with two textfields and one textarea.
my initial sample code:
@page = @agent.get "thewebsiteItold"
form = @page.form_with(:id => 'form')
textarea_values = "value1\nvalue2"
form['to'] = "username"
form['subject'] = "somesubject"
form['text'] = textarea_values
button = form.button_with(:name => "send")
@agent.click_button button
Although the form had this html:
<form method="post" action="/somethingyoudontneedtoknow" name="header" id="form">
running my script returned this error:
in 'method_missing': undefined method `id' for #<Mechanize::Form:0x21efb98> (NoMethodError)
Ok, so I changed the id for name and got another problem: the
in `<main>': undefined method `click_button' for #<Mechanize:0x253f380> (NoMethodError)
Before you tell me, I double checked the contents of "button", which holded the correct button I wanted to press to fire the form action.
So I changed it accordingly to these mechanize examples and the code worked well:
form = @page.form_with(:name => 'header')
textarea_values = "value1\nvalue2"
form['to'] = "username"
form['subject'] = "anotherboringsubject"
form['text'] = textarea_values
button = form.button_with(:name => "send")
@agent.submit(form, button)
and, well, it worked like expected:
Conclusion: Check if your original code is too far from what you posted us or the version of mechanize is the same as the link I passed before
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With