问题
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()
回答1:
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.
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.
回答2:
To simulate click event on Sales History & Tax Information tab, you can use the following line of code :
driver.find_element_by_xpath("//ul[@class='navbar nav-pills nav hasOverflow']//li[@role='tab']/a").click()
来源:https://stackoverflow.com/questions/48732196/simulate-click-event-using-selenium-in-python