我试图通过网页上的一个功能来实现以下功能。在
1)找到匹配文本的tr(这将是字段) 2) 在同一个tr中找到它的类型(可以是checkbox、textbox或select dropdown)。这将是输入值字段。 3) 输入值
到目前为止,我得到的是:
class pageCommon(Page):
def __init__(self, driver, field):
self.driver = driver
self.text = self.driver.find_element_by_xpath("//tbody/tr[%s]" % field)
# checkbox type is checkbox
def click_checkbox(self, checkboxvalue):
self.row.find_element_by_xpath('./td/input[@type="checkbox"]').click()
# dropbox type is hidden in the html code
def select_dropdown(self, dropdownvalue):
Select(self.row.find_element_by_xpath('./td/input[@type="hidden"]').select_by_visible_text(text)
def enterText(self, text):
self.row.find_element_by_xpath('./td/input[@type="checkbox"]').sendkeys("test")
1)这是复选框的HTML代码
2)以下是文本框的HTML代码:
3)下拉列表的HTML代码如下:
我不懂python,但我可以试着描述一下如何解决这些问题:
1)要查找与文本匹配的tr,可以使用以下xpath:
2)要找到输入类型,必须在tr中找到与文本匹配的输入。找到输入后,从元素中获取type属性。要查找输入,可以尝试以下xpath:
^{pr2}$3)现在需要根据每个输入类型输入值。在
相关问题 更多 >
编程相关推荐