尝试使用selenium阅读下表时遇到困难。
定位器如下
import pandas as pd
from bokeh.plotting import Figure
from bokeh.models import ColumnDataSource, TextInput, Button, Panel, Tabs, Label, DataTable, TableColumn
from bokeh.layouts import Row, Column, widgetbox
from bokeh.io import curdoc, show, output_notebook, gridplot
from sqlalchemy import create_engine
engine = create_engine('postgresql+psycopg2://username:password@domain.local:5432/dbname')
def main():
layout = gridplot([[retreive_descriptions()]])
curdoc().add_root(layout)
def retreive_descriptions():
df = pd.read_sql(sql='SELECT description from public."Description_Categories" WHERE category=\'Unknown\'', con=engine)
cds = ColumnDataSource(df)
columns = [TableColumn(field='description', title='Description'),TableColumn(field='category', title='Category')]
cat_data = DataTable(source=cds, columns=columns, editable=True)
return cat_data
@FindBy(css = "table.table-bordered.table-striped")
private WebElement storesTable;
运行代码时行数为0。非常感谢任何帮助。
答案 0 :(得分:1)
原因是:您提供的TagName
无效"/tbody/tr"
加上您需要更改storesTable
,因为tr
位于tbody
下面}:
@FindBy(css = "table.table-bordered.table-striped > tbody")
private WebElement storesTable;
并在更改tagName后:
List<WebElement> storeRows = storesTable.findElements(By.tagName("tr"));
答案 1 :(得分:0)
您提供xpath代替tagName。
如果你想使用下面的标记名是语句
List<WebElement> storeRows = storesTable.findElements(By.tagName("tr"));
否则,如果你想使用下面的xpath是声明。
List<WebElement> storeRows = storesTable.findElements(By.xpath(".//tbody/tr"));