简体   繁体   English

使用selenium从ExtJS网格行获取数据

[英]Get data from ExtJS grid row using selenium

Currently there are couple links that suppose to help with this task: general (1) and specific (2) approached. 目前有几个链接可以帮助完成这项任务: 一般 (1)和特定 (2)接近。

However (1) does not contain any code to start with and (2) contains only js one-liner. 但是(1)不包含任何开始的代码,(2)只包含js one-liner。

My question is how to get values from extjs-generated row cells? 我的问题是如何从extjs生成的行单元格中获取值?

For example, I've row element 例如,我有行元素

div#ext-gen-list-057-r.x-grid3-row.grid-rowcolor-black.grid-fontweight-normal.grid-fontstyle-normal.recordListRow.TableEvenRow.x-grid3-row-first.x-grid3-row-focus

where cells are represented like 细胞表示的地方

td.x-grid3-col.x-grid3-cell.x-grid3-td-0.x-grid3-cell-first

How do I get it's values using python and selenium webdriver? 如何使用python和selenium webdriver获取它的值?


UPD UPD

After some search there are few details revealed: 经过一番搜索后,透露的细节很少:

  1. Seems like browser.find_element(By.ID, 'element-id') will simply not work for ExtJS webpage as soon as document.getElementById('element-id') is null (correct me if it's wrong) 一旦document.getElementById('element-id')null browser.find_element(By.ID, 'element-id')看起来像browser.find_element(By.ID, 'element-id')根本不适用于ExtJS网页(如果错误,请纠正我)
  2. Proper way of getting Ext page is Ext.getBody('body-element-id') 获取Ext页面的正确方法是Ext.getBody('body-element-id')

However, there is no such method for Select in selenium.webdriver.support.ui that will allow to access body elements. 但是,在selenium.webdriver.support.ui中没有Select允许访问body元素的方法。

Thus, the issue has not yet been resolved. 因此,这个问题尚未得到解决。

May be this sample java code can help you. 可能是这个示例java代码可以帮到你。 It doesn't directly answer your question, but you can easily convert it to python and also get an insight into solving your problem. 它不直接回答您的问题,但您可以轻松地将其转换为python,并深入了解解决您的问题。

This code gets the extjs grid from the page, iterates through its rows to check if there is any cell containing the example id(1010294), then get the corresponding row and click the 8th cell on that row. 此代码从页面获取extjs网格,遍历其行以检查是否有任何包含示例id的单元格(1010294),然后获取相应的行并单击该行上的第8个单元格。 8th cell contains a button to click. 第8个单元格包含一个单击按钮。

WebElement editCustTable = driver.findElement(By.className("x-grid-table"));
List<WebElement> tableRows = editCustTable.findElements(By.tagName("tr"));
for (Iterator iterator = tableRows.iterator(); iterator.hasNext();) {
    WebElement row = (WebElement) iterator.next();              
    // if tr contains id = '1010294'            
    if(row.getAttribute("id").contains("1010294")){
        List<WebElement> tds = row.findElements(By.tagName("td"));
        tds.get(8).click();
        break;
        }       
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM