Localización, introducción de un valor en un cuadro de texto mediante Selenium y Python


<div class="MY_HEADING_A">
    <div class="TitleA">My title</div>
    <div class="Foobar"></div>
        <div class="PageFrame" area="W">                
             <span class="PageText">PAGE <input id="a1" type="txt" NUM="" />  of <span id="MAX"></span> </span>
</div>

Tengo el código anterior y estoy tratando de usar selenium para ingresar un valor de NUM aquí está el código que he escrito:

head = driver.find_element_by_class_name("MY_HEADING_A")
frame_elem = head.find_element_by_class_name("PageText")

# Following is a pseudo code. 
# Basically I need to enter a value of 1, 2, 3 etc in the textbox field (NUM) 
# and then hit RETURN key.
## txt  = frame_elem.find_element_by_name("NUM")
## txt.send_keys(Key.4"

¿Cómo obtener este elemento e introducir un valor?

Author: guaka, 2013-09-01

1 answers

Suponiendo que su página está disponible en " http://example.com "

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://example.com")

Seleccionar elemento por id:

inputElement = driver.find_element_by_id("a1")
inputElement.send_keys('1')

Ahora puedes simular pulsar ENTER:

inputElement.send_keys(Keys.ENTER)

O si es un formulario puede enviar:

inputElement.submit() 
 68
Author: zero323,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-09-01 11:33:23