【发布时间】:2015-11-23 22:41:25
【问题描述】:
我有以下情况:
我正在使用selenium python binding向网页发送一个单词,该网站执行一些处理(在包含它的silabes中划分单词)并将结果显示给用户,如下图所示:
词:竞争
结果:单词“竞争”分为 silabes
在检查元素工具中,我一直在检查输入文本的 id 属性
通过 selenium Web 驱动程序 API 从以下 python 脚本,我向搜索输入文本发送一些单词,然后按 ENTER 键执行操作。
# Currently supported WebDriver implementations are Firefox, Chrome, Ie and Remote
from selenium import webdriver
# Interacting with the RETURN KEY
from selenium.webdriver.common.keys import Keys
# Creating a web driver firefox instance
driver = webdriver.Firefox()
# With the get method we go to the webpage in the url given
driver.get("http://tip.iatext.ulpgc.es/silabas/Default.aspx")
# Assertion that checks if the word "Silabeador" is in the title webpage
assert "Silabeador" in driver.title
# WebDriver let me interact with items in a web page through of their attributtes
# More information http://selenium-python.readthedocs.org/locating-elements.html#locating-elements
elem = driver.find_element_by_id("MainContent_TextBox1")
elem.send_keys("Competencia")
elem.send_keys(Keys.RETURN)
# Four different types of call the same content position
print (driver.find_element_by_id("MainContent_Table1"))
print (driver.find_element_by_tag_name("table"))
print (driver.find_element_by_xpath('//div/table[1]'))
print (driver.find_element_by_xpath("//form[@id='Form1']//table[@id='MainContent_Table1']"))
# Call the form that contain all output information
print (driver.find_element_by_xpath("/html/body/form[1]"))
#print (driver.page_source)
assert "No results found" not in driver.page_source
driver.close()
当我执行脚本时,我的输出如下:
- 打开firefox浏览器,输入发送的单词,执行“enter”表单动作
我在打印指令中的输出如下:
/home/bgarcial/.virtualenvs/test/bin/python /home/bgarcial/workspace/Test/example/search.py
<selenium.webdriver.remote.webelement.WebElement (session="7f1ace67-0fb3-42b6-9cc9-af9c58b1715e", element="{320d5570-1060-4d4a-a5e6-af557f28f228}")>
<selenium.webdriver.remote.webelement.WebElement (session="7f1ace67-0fb3-42b6-9cc9-af9c58b1715e", element="{320d5570-1060-4d4a-a5e6-af557f28f228}")>
<selenium.webdriver.remote.webelement.WebElement (session="7f1ace67-0fb3-42b6-9cc9-af9c58b1715e", element="{320d5570-1060-4d4a-a5e6-af557f28f228}")>
<selenium.webdriver.remote.webelement.WebElement (session="7f1ace67-0fb3-42b6-9cc9-af9c58b1715e", element="{320d5570-1060-4d4a-a5e6-af557f28f228}")>
<selenium.webdriver.remote.webelement.WebElement (session="7f1ace67-0fb3-42b6-9cc9-af9c58b1715e", element="{d16859b4-2029-4ba9-8eeb-d3c8371053eb}")>
Process finished with exit code 0
在元素属性中返回我要问的元素形式的对象表示或内存地址(?-这是对的吗?-)...
我如何检索内容或信息,在这种情况下,处理“竞争”一词,这种情况分为 silabes (Comp-pe-ti-tion) 而不是我当前收到的字符串或表示?
谢谢
【问题讨论】:
标签: python selenium selenium-webdriver