【发布时间】:2020-12-30 13:18:32
【问题描述】:
以下 Selenium 自动化脚本可以正确打开给定的 URL,并打开查看发票选项卡,该选项卡会打开详细的发票。 我需要从详细发票中获取一些值,例如数字、日期和表格值。这些值非常嵌套以正确获取它们。单击查看发票时打开的 URL,我不知道如何抓取它或使用 selenium 继续。 代码中的元素是否类似于获取打开的详细发票页面的值的实例,还是有一些不同的方法?
代码如下:
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'D:/Chrome driver/chromedriver.exe') # Get local session(use webdriver.Chrome() for chrome)
driver.implicitly_wait(3)
driver.get("URL") # load page from some url
driver.find_element_by_xpath("//input[@id='PNRId']").send_keys("MHUISZ")
driver.find_element_by_xpath("//input[@id='GstRetrievePageInteraction']").click()
element = driver.find_element_by_name('ViewInvoice')
element.click()
谁能指导我如何从发票页面获取值?
【问题讨论】:
-
您好,如果您想简单地获取这些标签的值,请先找到元素。然后使用 .text。
-
嗨,Arundeep,为了找到标签,我使用了元素来查找标签,并且确实使用了 .text 方法。但它给出了 NoSuchElementException: no such element: Unable to locate element。我想使用这个“element = driver.find_element_by_name('ViewInvoice')”元素来获取值吗?
-
当您遇到 nosuchelement 异常时,有多种原因可能导致您无法获得它,请尝试将 driver.findbyelemet 包装在 webdriver 等待中。
-
你想获取下一页的值。
-
element.click() 打开一个详细页面,我需要为此获取该页面的值,我想使用哪个定位器来使用元素或驱动程序?我尝试用等待包装它不起作用。
标签: python html selenium automation