按顺序删除表中的python硒中的行

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

我有这样的html

链接到html

http://threedonthemap.s3-website.ap-south-1.amazonaws.com/


<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Easy Drag and Drop HTML Table Rows With jQuery</title>
    <!-- Bootstrap core CSS -->
    <link href="https://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Custom styles for this template -->
    <link href="https://getbootstrap.com/docs/4.0/examples/starter-template/starter-template.css" rel="stylesheet">
  </head>

  <body>

    <main role="main" class="container">

     <table class="table table-striped table-hover">
        <thead class="thead-dark">
            <tr>
                <th>Id</th>
                <th>Jabcode</th>
            </tr>
        </thead>
        <tbody>
            <tr>
              <td>01</td>
              <td>E24.9</td>
            </tr>
            <tr>
              <td>02</td>
              <td>J92.9</td>
            </tr>
            <tr>
              <td>03</td>
              <td>A10.2</td>
            </tr>
            <tr>
              <td>04</td>
              <td>B10.2</td>
            </tr>
            <tr>
              <td>05</td>
              <td>C4.9</td>
            </tr>
            <tr>
              <td>06</td>
              <td>D10.11</td>

            </tr>
            <tr>
              <td>07</td>
              <td>F19.10</td>             
            </tr>

        </tbody>
    </table>

    </main><!-- /.container -->

    <!-- Bootstrap & Core Scripts -->
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> 
    <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script> 
    <script src="https://getbootstrap.com/dist/js/bootstrap.min.js"></script>

    <script type="text/javascript">
      $('tbody').sortable();
    </script>

  </body>
</html>

当前在网页上有哪个特定顺序

enter image description here

我想根据我在python程序中提供的参数来更改网页中项目的顺序。

这是我的python代码

from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
import time 

jab_code_order =['J92.9','A10.2','E24.9','B10.2','F19.10','D10.11','C4.9']
    # browser = 

driver = webdriver.Chrome('/chromedrivernew')
driver.get("file:////datasets/demodragable/index.html")





for item in jab_code_order:
    cell=driver.find_element_by_xpath("//tr[@class='ui-sortable-handle']//td[text()='"+ item + "']")
    print(cell.text)
    source_element = driver.find_element_by_xpath("//tr[@class='ui-sortable-handle']//td[text()='"+ item + "']")
    dest_element = driver.find_element_by_xpath("//tr[@class='ui-sortable-handle']//td[text()='A10.2']")
    ActionChains(driver).drag_and_drop(source_element, dest_element).perform()
    time.sleep(2)

使用当前代码,它来是这样的

enter image description here

我想要这样的表顺序

enter image description here

是否有任何pythonic方式而不是循环遍历?

任何帮助将不胜感激!

python selenium selenium-webdriver selenium-chromedriver selenium-ide
1个回答
2
投票
这是面试问题吗?你还有更多给我吗?
© www.soinside.com 2019 - 2024. All rights reserved.