【发布时间】:2017-12-06 03:06:06
【问题描述】:
我试图在 python 中创建一个通用方法来使用任何定位器策略来查找 webelement 的子元素。目前我有下面的代码,请帮助完成下面代码中的getchildobject方法。此方法应该能够使用任何定位器(如 xpath、css 或 id 等)找到 webelement 的子元素
getelement="xpath=//div[@id='test']"
def get_webelement_Cus(locator):
strategy=locator.split("=")[0]
locator=locator.replace(locator.split("=")[0]+"=","")
if strategy.uppercase()=='XPATH':
return driver.find_elements_by_xpath(locator)
elif strategy.uppercase()=='CSS':
return driver.find_element_by_css_selector(locator)
else:
return None
def getchildobject(webelement,locator):
webelement.????????
【问题讨论】: