在 python 中使用 selenium 模拟点击事件
Simulate Click event using selenium in python
我正在从中抓取一些数据 link
https://www.vbgov.com/property-search#DetailView=14760123360000。但是我无法使用 webdriver Selenium 和 python.
在 "Sales History & Tax Information" 选项卡上模拟点击事件
driver.get("https://www.vbgov.com/property-search#")
searchBox1 = driver.find_element_by_id("consolidated-search-query")
searchBox1.send_keys("1124 LUKE DR")
searchBox1.send_keys(Keys.ENTER)
driver.implicitly_wait(5)
link = driver.find_element_by_xpath('//*[@id="property"]/tbody/tr/td[2]/a')
link.click()
elem = driver.find_element_by_xpath('//*[@id="property-counts"]/h4')
tab = driver.find_element_by_partial_link_text("Sales History & Tax Information")
tab.click()
要在销售历史和税务信息 选项卡上模拟点击事件,您可以使用以下代码行:
driver.find_element_by_xpath("//ul[@class='navbar nav-pills nav hasOverflow']//li[@role='tab']/a").click()
您正在尝试单击 'Sales History & Tax Information tab' 并且它也发生了,但它发生在页面加载时,默认情况下在页面加载后导航到 'land/Building Information' 选项卡。所以我在这里等待页面加载,然后点击 'Sales History & Tax Information tab' 等待 'property blue prints' 加载。
在单击 'Sales History & Tax Information tab' 之前使用 time.sleep 在这里也有效,但不是可取的。
searchBox1 = driver.find_element_by_id("consolidated-search-query")
searchBox1.send_keys("1124 LUKE DR")
searchBox1.send_keys(Keys.ENTER)
driver.implicitly_wait(5)
link = driver.find_element_by_xpath('//*[@id="property"]/tbody/tr/td[2]/a')
link.click()
elem = driver.find_element_by_xpath('//*[@id="property-counts"]/h4')
wait.until(EC.presence_of_element_located((By.XPATH, "//*[text()='Land Information']")))
wait.until(EC.visibility_of_element_located((By.XPATH, "//div[@class='band visible ready']")))
wait.until(EC.visibility_of_element_located((By.XPATH, "//a[text()='Sales History & Tax Information']"))).click()
希望这能解决您的问题。
我正在从中抓取一些数据 link https://www.vbgov.com/property-search#DetailView=14760123360000。但是我无法使用 webdriver Selenium 和 python.
在 "Sales History & Tax Information" 选项卡上模拟点击事件driver.get("https://www.vbgov.com/property-search#")
searchBox1 = driver.find_element_by_id("consolidated-search-query")
searchBox1.send_keys("1124 LUKE DR")
searchBox1.send_keys(Keys.ENTER)
driver.implicitly_wait(5)
link = driver.find_element_by_xpath('//*[@id="property"]/tbody/tr/td[2]/a')
link.click()
elem = driver.find_element_by_xpath('//*[@id="property-counts"]/h4')
tab = driver.find_element_by_partial_link_text("Sales History & Tax Information")
tab.click()
要在销售历史和税务信息 选项卡上模拟点击事件,您可以使用以下代码行:
driver.find_element_by_xpath("//ul[@class='navbar nav-pills nav hasOverflow']//li[@role='tab']/a").click()
您正在尝试单击 'Sales History & Tax Information tab' 并且它也发生了,但它发生在页面加载时,默认情况下在页面加载后导航到 'land/Building Information' 选项卡。所以我在这里等待页面加载,然后点击 'Sales History & Tax Information tab' 等待 'property blue prints' 加载。
在单击 'Sales History & Tax Information tab' 之前使用 time.sleep 在这里也有效,但不是可取的。
searchBox1 = driver.find_element_by_id("consolidated-search-query")
searchBox1.send_keys("1124 LUKE DR")
searchBox1.send_keys(Keys.ENTER)
driver.implicitly_wait(5)
link = driver.find_element_by_xpath('//*[@id="property"]/tbody/tr/td[2]/a')
link.click()
elem = driver.find_element_by_xpath('//*[@id="property-counts"]/h4')
wait.until(EC.presence_of_element_located((By.XPATH, "//*[text()='Land Information']")))
wait.until(EC.visibility_of_element_located((By.XPATH, "//div[@class='band visible ready']")))
wait.until(EC.visibility_of_element_located((By.XPATH, "//a[text()='Sales History & Tax Information']"))).click()
希望这能解决您的问题。