使用selenium python web驱动程序从角度单击表格中的所有行

问题描述 投票:2回答:1

我试图在HTML页面的表格/网格上迭代某一行的行,我假设它是一个动态角度元素。

我试图通过创建每行之间的常见xpath列表来遍历行。这只能帮助我实现32行而不是332的全部金额。我也试着等待网页是否会加载然后拥有全部的网络元素。然后我尝试通过向下滚动到列表中的最后一个元素来运行搜索类似xpath的循环。这些方法都没有帮助我遍历行。此外,由于该网站是私人网站,我将无法共享该网站。

python

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)

html for the rows

<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&nbsp;
  <span title="Open defect(s) on site"
        ng-show="row.entity.openDeficiencies"
        style="background-color:yellow; color:#000;"
        class="ng-hide">
    &nbsp;!&nbsp;
  </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

python html angularjs selenium selenium-webdriver
1个回答
0
投票

您仍然可以通过附加到类名来增加每个链接,因为它们在性质上似乎有点独特,并且使用最后一个数字作为字母表中的字符。也许像下面这样的东西可以工作:)扩展classname的最后一个字符,如果有增加,应该解决超过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()
© www.soinside.com 2019 - 2024. All rights reserved.