【问题标题】:How do we access anchor tag link embedded inside ul and li tags to open the link associated with that tag using selenium with python我们如何访问嵌入在 ul 和 li 标签中的锚标签链接,以使用 selenium 和 python 打开与该标签关联的链接
【发布时间】:2020-09-07 04:27:35
【问题描述】:

我需要使用 id=ViewInvoice 打开该锚标记的链接。我怎么做?附加 HTML 页面的快照。 快照:

这是我需要打开黄色突出显示的快照:

代码如下:

从硒导入网络驱动程序

driver = webdriver.Chrome(executable_path='C:/webdrivers/chromedriver.exe') # 获取本地会话(使用 webdriver.Chrome() for chrome) driver.get("the url") # 从某个 url 加载页面

driver.find_element_by_xpath("//input[@id='PNRId']").send_keys("MDGLRY") driver.find_element_by_xpath("//input[@id='GstRetrievePageInteraction']").click()

link = driver.find_elements_by_id("ViewInvoice")[0] 链接.click()

【问题讨论】:

    标签: python html selenium webdriver


    【解决方案1】:

    可以通过id获取元素,然后使用.click()

    link = driver.find_element_by_id("ViewInvoice")
    link.click()
    

    或

    link = driver.find_elements_by_id("ViewInvoice")[0]
    link.click()
    

    【讨论】:

    • 嗨,它不工作。它给出了一个错误“JavascriptException: javascript error: Cannot read property 'style' of null”。
    • “NtOpenThread: {Access Denied} 进程已请求访问对象,但尚未被授予这些访问权限。(0xc0000022) 进程中未找到线程 ID 43952”。这是我在调试错误日志中得到的错误。我已经尝试过 driver.find_element_by_css_selector("gst-view-print-btn ViewInvoice clsDtmPageInteraction"),但这也不起作用。
    • 您好,也尝试了第二种解决方案,但无法打开查看发票。
    • @AAYUSH LAKHANI 你能帮我解决吗?
    • 它给出了以下错误 NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"[id="ViewInvoice"]" }.
    猜你喜欢
    • 2018-12-12
    • 2011-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多