2 回答
TA贡献1111条经验 获得超0个赞
该表包含 GST 发票编号,需要一些时间来加载“GST 发票编号”。在读取数据进行比较之前等待一段时间。检查下面的代码,提取发票编号并比较第三位数字,然后单击“查看发票”链接查看发票
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()
driver.get("URL")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='PNRId']"))).send_keys("SHFYGW")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='GstRetrievePageInteraction']"))).click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, "gst-invoice-list.list-inline")))
elements = driver.find_elements(By.CLASS_NAME, "gst-invoice-list.list-inline")
for ele in elements:
eleText = ele.find_element_by_tag_name("li").text
if eleText[2]=='2':
print(eleText)
#ele.find_element(By.ID, 'ViewInvoice').click()
driver.execute_script("arguments[0].click()", ele.find_element(By.ID, 'ViewInvoice'));
#break
driver.quit()
TA贡献1864条经验 获得超2个赞
目前没有正则表达式,只能通过 xpath 查找。
driver.implicitly_wait(5)
uls = driver.find_elements_by_xpath("//ul[@class='gst-invoice-list list-inline']//li")
for url in uls:
if url.text[2]=='2': #^..2 would be a simple regex for digit 2 on 3rd index
print (url.text)
显示以下内容
MH2192004AA58892
MP2192004AA05359
添加回答
举报