【发布时间】:2020-09-14 16:22:08
【问题描述】:
我需要遍历一个表来获取“GST Invoice No.”的值。并仅打开第三位为数字 2 的发票编号的“查看发票”表。
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome(executable_path=r'D:/Chrome driver/chromedriver.exe') # Get local session(use webdriver.Chrome() for chrome)
driver.get("URL")
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//input[@id='PNRId']"))).send_keys("SHFYGW")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='GstRetrievePageInteraction']"))).click()
#print(toJourney.find_element_by_xpath('/tbody/tr/td[2]/ul'))
如何继续迭代表?我尝试了以下方法,但它只给出一个值
uls = driver.find_elements(By.CLASS_NAME, "gst-invoice-list.list-inline")
我如何迭代以仅在第三位打开具有数字 2 的那个?
【问题讨论】:
-
您好,问题出在哪里?
-
您好,对于不同的 PNRS,发票是分散的,没有按特定顺序排列。我想打开那些 GST Invoice No 的第三位数字为 2 的发票。如何循环并获取这些发票?
-
您可以使用带有 ul[class='gst-invoice-list list-inline']/li 的 xpath 而不是正则表达式 /text()='' 来匹配。
-
这会检查所有的消费税号码吗?
-
您需要在此之后使用 /text()='' 并检查第 3 位中的数字 2。
标签: python html selenium selenium-webdriver