在python中使用Selenium模拟Click事件 [英] Simulate Click event using selenium in python

查看:68
本文介绍了在python中使用Selenium模拟Click事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从此链接中抓取一些数据 https://www.vbgov.com/property-search#DetailView=14760123360000.但是我无法使用Webdriver Selenium和python模拟销售历史和税收信息"选项卡上的点击事件.

I am scraping some data from this link https://www.vbgov.com/property-search#DetailView=14760123360000. But i am unable to simulate click event on "Sales History & Tax Information" tab using webdriver Selenium and python.

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

推荐答案

您正在尝试点击销售历史记录&税务信息标签"及其发生的情况,但默认情况下是在页面加载时发生的,在页面加载后默认情况下,它导航到土地/建筑信息"标签.因此,在这里,我正在等待页面加载,然后再点击销售历史记录&等待属性蓝图"加载完毕,然后单击税务信息"标签.

You are trying to click on the 'Sales History & Tax Information tab' and its happening too , but it is happening while the page loads and after page load by default it is navigate to 'land/Building Information' tab. So here i am waiting for page to load before clicking on 'Sales History & Tax Information tab' by waiting till 'property blue prints' loads.

使用time.sleep,然后点击销售历史记录&税务信息"标签也可以在此处使用,但不是首选.

Using time.sleep before clicking 'Sales History & Tax Information tab' also works here but not preferable.

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

希望这可以解决您的问题.

Hope this will solve your problem.

这篇关于在python中使用Selenium模拟Click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆