Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取包含特定文本的td,然后查找其父母和兄弟姐妹_Python_Html_Selenium_Selenium Webdriver - Fatal编程技术网

Python 获取包含特定文本的td,然后查找其父母和兄弟姐妹

Python 获取包含特定文本的td,然后查找其父母和兄弟姐妹,python,html,selenium,selenium-webdriver,Python,Html,Selenium,Selenium Webdriver,我试图使用Python-Selenium从包含一些特定文本的表中查找元素,我能够得到它。但当我对所选元素调用parent方法时,它会返回表的实例,而不是表的父行。我现在做的是 driver = webdriver.Firefox() driver.get('http://www.example.com') WebDriverWait(driver, self.explicit_wait).until( EC.presence_of_element_located((By.ID,

我试图使用
Python-Selenium
从包含一些特定文本的表中查找
元素,我能够得到它。但当我对所选元素调用parent方法时,它会返回表的实例,而不是表的父行。我现在做的是

driver = webdriver.Firefox()
driver.get('http://www.example.com')
WebDriverWait(driver, self.explicit_wait).until(
        EC.presence_of_element_located((By.ID, "table-id"))
        )
td = driver.find_element_by_xpath("//*[contains(text(), 'some texts')]"
parent_row = td.parent    # get the parent of td element
但是在父行中,驱动程序返回的是表实例,而不是行实例。
将非常感谢您的帮助

根据Webdriver,无法直接使用Webdriver获取父元素。selenium Python绑定中的
WebElement的
,在内部使用,不引用元素的直接父元素。它指的是您在以下位置调用的
find\u element\u by.*
WebDriver
实例:

parent

找到此元素的WebDriver实例的内部引用

可以使用xpath获取父元素:

parent_row = td.find_element_by_xpath("..")