第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何迭代表并打開滿足條件的選項(xiàng)卡

如何迭代表并打開滿足條件的選項(xiàng)卡

函數(shù)式編程 2023-08-08 09:55:50
我需要迭代一個(gè)表來獲取“GST 發(fā)票號(hào)”的值。并打開僅包含第三位為數(shù)字 2 的發(fā)票號(hào)的“查看發(fā)票”表。from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as ECdriver = 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'))如何繼續(xù)迭代表?我嘗試了以下方法,但它只提供了一個(gè)值uls = driver.find_elements(By.CLASS_NAME, "gst-invoice-list.list-inline")如何迭代只打開第三位數(shù)字為 2 的數(shù)字?
查看完整描述

2 回答

?
catspeake

TA貢獻(xiàn)1111條經(jīng)驗(yàn) 獲得超0個(gè)贊

該表包含 GST 發(fā)票編號(hào),需要一些時(shí)間來加載“GST 發(fā)票編號(hào)”。在讀取數(shù)據(jù)進(jìn)行比較之前等待一段時(shí)間。檢查下面的代碼,提取發(fā)票編號(hào)并比較第三位數(shù)字,然后單擊“查看發(fā)票”鏈接查看發(fā)票


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()


查看完整回答
反對(duì) 回復(fù) 2023-08-08
?
慕斯王

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超2個(gè)贊

目前沒有正則表達(dá)式,只能通過 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)

顯示以下內(nèi)容


MH2192004AA58892

MP2192004AA05359


查看完整回答
反對(duì) 回復(fù) 2023-08-08
  • 2 回答
  • 0 關(guān)注
  • 157 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)