Problemas al manejar un campo de texto ya que al hacer clic en él se abre una ventana emergente
Frecuentes
Visto 234 veces
0
I have problem entering text in a text_field as when the script tries to enter anything in the field, it throws a popup. When manually entering, it does not throw a popup. The html of the text field is as below.
<input name="txtperc" type="text" value="0" maxlength="3" id="txtperc" tabindex="1" class="textBox valid" data-setfocus="true" onchange="return OnChangePercentAssignment('1','1');" onkeypress="return restrictKeyPress(event);" onpaste="cleanText.Wait(this)" style="width:30px;">
My code =
text_field(:percentage ,:id=>'txtperc')
self.percentage = 100
My guess is that the script tries to clear the text field and that is triggering the pop up to fire.
También probé
text_field(:percentage ,:id=>'txtperc')
self.percentage = 10
browser.alert.ok
self.percentage = 100
Is there an alternate way to set/type into the text_field?
1 Respuestas
1
The application behaviour seems a bit strange. You might have to bypass the input element's event by executing javascript to set the field. This assumes that the event's being fired can be ignored.
You could define the page object as:
class MyPage
include PageObject
text_field(:percentage ,:id=>'txtperc')
def percentage=(value)
execute_script("document.getElementById('txtperc').value = '#{value}';")
end
end
And then input the field as normal:
self.percentage = 100
respondido 27 nov., 13:15
Thank you Justin...Let me try this....However, I did try the same in Watir/Ruby1.8.7 environment...It worked just fine... I also tried in 1.9/Watir-webdriver-> It did NOT work. - mkum
That did it! Thank you Justin. However,when I just set it in Watir, it worked with no problems....something fishy in watir-webdriver/Page-Object. Also, is it necessary to define text_field(:percentage ,:id=>'txtperc')?? your code did work without that as well..but wanted to know if you any reasons for that.. - mkum
What happened when you set it webdriver/page-object? It seemed to work when I tried (though I changed the javascript in the input's events). You do not need to define the text_field(:percentage ,:id=>'txtperc')
. I just like to do it to ensure that the page object has the expected methods for the percentage field - ie percentage
(to get the value), percentage=
(to input the value) and percentage_element
(to get the page-object element). - justin ko
When I tried in watir-webdriver/pageobject/ruby 1.9, the popup came up as soon as the script tried to enter a value in the text field. It just worked fine in watir/ruby187..... the default value of the text_field is 0. This default value gets cleared before the text field is being set and hence trigerring the popup -I guess. - mkum
When you say "watir/ruby187", is that "watir-classic" (ie driving IE)? - justin ko
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas watir-webdriver page-object-gem or haz tu propia pregunta.
It seems a bit strange that the manual and automated entries would behave differently. What does the popup say? I assume it is complaining about the value inputted? - Justin Ko
You are correct. It says enter a number between 0 to 100. I notice that the field is cleared and the popup is triggered. - mkum