我正在尝试遍历HTML页面的表格/网格上某行的特定列,并假设它是动态角度元素。
我试图通过在每行之间创建一个常见xpath的列表来遍历行。这只能帮助我获得32行,而不是全部332行。我还尝试等待网页是否加载,然后拥有全部Web元素。然后,我尝试通过向下滚动到列表中的最后一个元素来运行循环,以搜索相似的xpath。这些方法都没有帮助我遍历行。另外,由于该网站是私人网站,因此我将无法共享该网站。
webelement = []
driver.implicitly_wait(20)
ranSleep()
for webelement in driver.find_elements_by_xpath('//a[@class="ng-pristine ng-untouched ng-valid ng-binding ng-scope ng-not-empty"]'):
driver.implicitly_wait(20)
<a ng-model="row.entity.siteCode"
ng-click="grid.appScope.openSite(row.entity)"
style="cursor:pointer"
class="ng-pristine ng-untouched ng-valid ng-binding ng-scope ng-not-empty">
Albuquerque
<span title="Open defect(s) on site"
ng-show="row.entity.openDeficiencies"
style="background-color:yellow; color:#000;"
class="ng-hide">
!
</span>
</a>
解决后,我希望能够单击每一行中的所有链接
这是html代码的片段
<div id="table1" class="container-fluid">
<div ui-i18n="en"
class="grid advanceSearch ui-grid ng-isolate-scope grid1554731599680"
id="grid1" ui-grid="gridOptions"
ui-grid-expandable="" ui-grid-rowedit=""
ui-grid-resize-columns="" ui-grid-selection=""
ui-grid-edit="" ui-grid-move-columns="">
<!-- TODO (c0bra): add "scoped" attr here, eventually? -->
<style ui-grid-style="" class="ng-binding">
.grid1554731599680 {
/* Styles for the grid */
}
here is how the page looks with the table format
Here is the rows that I want to click through all of them
答案 0 :(得分:0)
您可能仍然可以通过在类名称后附加每个链接来增加链接,因为它们在本质上似乎有点独特,并使用最后一个数字作为字母中的字符。也许下面的方法可能会起作用:)扩展类名的最后一个字符(如果有增加的话)应解决超过26个的问题。
已采取的步骤:增加类名>追加成功列表>移动到列表中的链接>单击链接>列表项
import string
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
alpha = string.ascii_uppercase
successfulIncs = []
for char in alpha:
className = 'ng-pristine.ng-scope.ui-grid-coluiGrid-000' + char
try:
driver.find_elements_by_class_name(className)
successfullIncs.append(className)
except NoSuchElementException:
print("Element not found")
### First move to our element
for line in successfulIncs:
link = WebDriverWait(driver, 3).until(EC.visibility_of_element_located
(By.CLASS_NAME, line))
ActionChains(driver).move_to_element(link).perform()
#Click
ActionChains(driver).move_to_element(link).click(link).perform()