Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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
Selenium Python如何从元素表中查找指定的行和列_Python_Python 2.7_Selenium_Selenium Webdriver - Fatal编程技术网

Selenium Python如何从元素表中查找指定的行和列

Selenium Python如何从元素表中查找指定的行和列,python,python-2.7,selenium,selenium-webdriver,Python,Python 2.7,Selenium,Selenium Webdriver,我有一个包含一些行和列的表。我想遍历该表,找到第81行和第82行以及第4列索引(姓氏列) 我想检查第4列中第81行和第82行的值。 数据是固定的,因此为我的测试目的识别第81行和第82行是可以的 我已经开始编写一些代码来获取表并遍历行。 如何直接转到第81行和第4列 我的代码片段是: def is_surname_Campbell_and_CAMPBELL_together(self): # is the surname "Campbell" and "CAMPBELL" together

我有一个包含一些行和列的表。我想遍历该表,找到第81行和第82行以及第4列索引(姓氏列) 我想检查第4列中第81行和第82行的值。 数据是固定的,因此为我的测试目的识别第81行和第82行是可以的

我已经开始编写一些代码来获取表并遍历行。 如何直接转到第81行和第4列

我的代码片段是:

def is_surname_Campbell_and_CAMPBELL_together(self): # is the surname "Campbell" and "CAMPBELL" together
    try:
        table_id = WebDriverWait(self.driver, 20).until(
            EC.presence_of_element_located((By.ID, 'data_configuration_view_preview_dg_main_body')))
        rows = table_id.find_elements(By.TAG_NAME, "tr")
        for row in rows:
            # Get the columns
            col_sname = row.find_elements(By.TAG_NAME, "td")[4]  # This is the SNAME column
            print "col_sname.text = "
            if col_sname.text == "Campbell":
                return True
        return False
    except NoSuchElementException, e:
        print "Element not found "
        print e
        self.save_screenshot("is_surname_Campbell_and_CAMPBELL_together")
        return False
HTML代码段(一个小部分,否则将太长而无法粘贴)


f1/48
基思
坎贝尔
谢谢,
Riaz

在常见情况下,81行4列中单元格的值可定义为

driver.find_element_by_xpath('//tr[81]/td[4]').text

PS.
HTML
元素索引从[1]元素开始,但不是从[0]开始,如在
Python

中,在常见情况下,81行4列中单元格的值可以定义为

driver.find_element_by_xpath('//tr[81]/td[4]').text

PS.
HTML
elements索引化从[1]元素开始,但不是从[0]开始,如
Python

提供
HTML
对于提供的表alsoHTML,感谢提供
HTML
对于提供的表alsoHTML,感谢这项工作并感谢提及索引。这是col 5的姓氏col。我现在知道了,谢谢。是的,这很有效,谢谢你提到索引。因为姓col,所以是col 5。我现在知道了,谢谢。