【问题标题】:How to open two links on the same browser如何在同一个浏览器上打开两个链接
【发布时间】:2020-12-31 04:30:45
【问题描述】:

我需要在其第三位打开 GST Invoice 编号包含数字 2 的 2 Invoices。我修改如下:

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

toJourney=WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "table.gst-table-view")))

toJourney.find_element_by_xpath('tbody/tr/td[2]/ul[1]/li[2]/a[1]').click()

toJourney.find_element_by_xpath('tbody/tr/td[2]/ul[3]/li[2]/a[1]').click() 

第一张发票正确打开,但第二张发票却给出了

ElementClickInterceptedException: element click intercepted: Element <a id="ViewInvoice" invoice-number="MP2192004AA05359" is-print="false" href="#" target="_blank" class="gst-view-print-btn ViewInvoice clsDtmPageInteraction" name="ViewInvoice">...</a> is not clickable at point (490, 559). Other element would receive the click: <a href="#" style="color: #f6e292">...</a>
  (Session info: chrome=85.0.4183.102)

我在这里做错了什么?

【问题讨论】:

  • driver.execute_script("arguments[0].click();", element) 元素有问题。所以抓住元素并像这样运行它。
  • 谢谢阿伦迪普。它起作用了,但为什么我们必须像这样抓取元素并执行?
  • 有一个元素挡住了路。位置明智。
  • 您好 arundeep,对于不同的 PNRS,发票是分散的,没有按特定顺序排列。我想打开那些 GST Invoice No 的第三位数字为 2 的发票。如何循环并获取这些发票?

标签: python html selenium automation


【解决方案1】:

它工作正常.. 使用以下代码.. 我已经检查过了。它在两个不同的选项卡中打开了两个 pdf。

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

def chrome_arguments():
    user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0'
    options= webdriver.ChromeOptions()
    options.add_argument('--incognito')
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    options.add_argument("--disable-plugins-discovery")
    options.add_argument('--disable-extensions')
    options.add_argument('--profile-directory=Default')
    options.add_argument("--start-maximized")
    options.add_argument("--no-sandbox")
    options.add_argument('--ignore-certificate-errors')
    options.add_argument('--safebrowsing-disable-download-protection')
    options.add_argument('--safebrowsing-disable-auto-update')
    options.add_argument('--disable-client-side-phishing-detection')
    options.add_argument(f'user-agent={user_agent}')
    
    return options
    
driver = webdriver.Chrome(executable_path='',options=chrome_arguments()) 

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

toJourney=WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "table.gst-table-view")))

toJourney.find_element_by_xpath('tbody/tr/td[2]/ul[1]/li[2]/a[1]').click()

toJourney.find_element_by_xpath('tbody/tr/td[2]/ul[3]/li[2]/a[1]').click()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-22
    • 1970-01-01
    • 2012-06-20
    • 2021-11-11
    • 2012-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多