Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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 2.7 Python中的Webdriver如何等待HTML表加载_Python 2.7_Selenium_Selenium Webdriver - Fatal编程技术网

Python 2.7 Python中的Webdriver如何等待HTML表加载

Python 2.7 Python中的Webdriver如何等待HTML表加载,python-2.7,selenium,selenium-webdriver,Python 2.7,Selenium,Selenium Webdriver,我将SeleniumWebDriver与Python一起使用。我在如何等待表完成加载时遇到问题 该网页显示一个列表(名称、变量、提要等)。每一行都有每一列的数据。例如,Lucy、姓名、数据源。我正在检查if语句中每一行的数据是否正确。我需要等待加载表中的所有行,以避免元素不再有效 等待加载整个表的最佳方式是什么? 我试过使用WebdriverWait。我想我的语法错了 我的代码是: def is_mappings_details_saved(self, name, dataset, feed,

我将SeleniumWebDriver与Python一起使用。我在如何等待表完成加载时遇到问题

该网页显示一个列表(名称、变量、提要等)。每一行都有每一列的数据。例如,Lucy、姓名、数据源。我正在检查if语句中每一行的数据是否正确。我需要等待加载表中的所有行,以避免元素不再有效

等待加载整个表的最佳方式是什么? 我试过使用WebdriverWait。我想我的语法错了

我的代码是:

def is_mappings_details_saved(self, name, dataset, feed, variable):
            try:
                #self.driver.implicitly_wait(10)
                wait = WebDriverWait(self.driver, 20)
                table_id = wait.until(EC.presence_of_element_located((By.ID, 'data_configuration_mappings_ct_fields_body')))
                rows = table_id.find_elements(By.TAG_NAME, "tr")
                for row in rows:
                    time.sleep(1)
                    # Get the columns
                    col_name = row.find_elements(By.TAG_NAME, "td")[1]  # This is the Name column
                    col_variable = row.find_elements(By.TAG_NAME, "td")[2]  # This is the Variable column
                    col_feed = row.find_elements(By.TAG_NAME, "td")[3]  # This is the Feed column
                    col_data_category = row.find_elements(By.TAG_NAME, "td")[4]  # This is the Data Category column
                    col_dataset = row.find_elements(By.TAG_NAME, "td")[6]  # This is the Dataset column
                    col_datamap = row.find_elements(By.TAG_NAME, "td")[7]  # This is the Datamap column
                    if (col_name.text == name) and (col_variable.text == variable) and (col_feed.text == feed) and (col_data_category.text == "Main") and (col_dataset.text == dataset) and (col_datamap.text == self.datamap_name):
                        return True
                return False
            except NoSuchElementException, e:
                return False
错误是:

raise exception_class(message, screen, stacktrace)
StaleElementReferenceException: Message: Element is no longer valid
rows = table_id.find_elements(By.TAG_NAME, "tr")
错误处突出显示的行是:

raise exception_class(message, screen, stacktrace)
StaleElementReferenceException: Message: Element is no longer valid
rows = table_id.find_elements(By.TAG_NAME, "tr")
我等待表加载,然后找到行。如果我有整张桌子,我不需要找到行吗

HTML代码段是:

<table id="data_configuration_mappings_ct_fields_body" cellspacing="0" style="table-layout: fixed; width: 100%;">
<colgroup>
<tbody>
    <tr class="GOFU2OVFG GOFU2OVMG" __gwt_subrow="0" __gwt_row="0">
    <td class="GOFU2OVEG GOFU2OVGG GOFU2OVHG GOFU2OVNG">
    <td class="GOFU2OVEG GOFU2OVGG GOFU2OVNG">
        <div __gwt_cell="cell-gwt-uid-418" style="outline-style:none;">
            <span class="linkhover" title="Name" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">Name</span>
        </div>
    </td>
    <td class="GOFU2OVEG GOFU2OVGG GOFU2OVNG">
        <div __gwt_cell="cell-gwt-uid-419" style="outline-style:none;">
            <span class="" title="Name" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">Name</span>
        </div>
    </td>
    <td class="GOFU2OVEG GOFU2OVGG GOFU2OVNG">
        <div __gwt_cell="cell-gwt-uid-420" style="outline-style:none;">
            <span class="" title="crm" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">crm</span>
        </div>
    </td>
    <td class="GOFU2OVEG GOFU2OVGG GOFU2OVNG">
        <div __gwt_cell="cell-gwt-uid-421" style="outline-style:none;">
            <span class="" title="Main" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">Main</span>
        </div>
    </td>
    <td class="GOFU2OVEG GOFU2OVGG GOFU2OVNG">
        <div __gwt_cell="cell-gwt-uid-422" style="outline-style:none;">
            <span class="" title="TITLE + FNAME + SNAME" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">TITLE + FNAME + SNAME</span>
        </div>
    </td>
    <td class="GOFU2OVEG GOFU2OVGG GOFU2OVNG">
        <div __gwt_cell="cell-gwt-uid-423" style="outline-style:none;">
            <span class="" title="CRM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">CRM</span>
        </div>
    </td>
        <td class="GOFU2OVEG GOFU2OVGG GOFU2OVNG">
        <td class="GOFU2OVEG GOFU2OVGG GOFU2OVBH GOFU2OVNG">
    </tr>
    <tr class="GOFU2OVEH" __gwt_subrow="0" __gwt_row="1">
        <td class="GOFU2OVEG GOFU2OVFH GOFU2OVHG">
            <div __gwt_cell="cell-gwt-uid-417" style="outline-style:none;">
                <input type="checkbox" tabindex="-1"/>
            </div>
        </td>
    <td class="GOFU2OVEG GOFU2OVFH">
        <div __gwt_cell="cell-gwt-uid-418" style="outline-style:none;">
            <span class="linkhover" title="DOB" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">DOB</span>
        </div>
    </td>
    <td class="GOFU2OVEG GOFU2OVFH">
    <td class="GOFU2OVEG GOFU2OVFH">
    ... etc     
    </tr>
</tbody>
</table>

名称
名称
客户关系管理
主要
TITLE+FNAME+SNAME
客户关系管理
出生日期
... 等

谢谢,里亚兹,我已经设法解决了。只需等待表容器加载即可。不要等待行和列。 我还将self.driver.implicitly_wait(20)放在基类中

class BasePage(object):

def __init__(self, driver):
    self.driver = driver
    self.driver.implicitly_wait(20)

class MappingsPage(BasePage):
    def is_mappings_details_saved(self, name, dataset, feed, variable):       
         table_id = WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((By.ID, 'data_configuration_mappings_ct_fields_body')))
         rows = table_id.find_elements(By.TAG_NAME, "tr")
         for row in rows:  
         # Get the columns
         col_name = row.find_elements(By.TAG_NAME, "td")[1]  
        col_variable = row.find_elements(By.TAG_NAME, "td")[2]  
    etc...

您的表格是否在任何事件之后出现?还是在手册页中加载?您的表是否有id、名称或唯一标识符?它将加载到主页中。表ID是数据\u配置\u映射\u ct\u字段\u正文您知道表中会加载多少行吗?.4行。客户端可以稍后输入更多数据,这样就可以结束10行或10行。换句话说,我正在尝试定义我们可以依赖的smth。作为一个人,你是如何定义表被加载的?有什么迹象吗?很高兴看到你解决了这个问题。当系统允许你这样做时,把你的答案标记为“接受”。