Home > other >  Cant find elements on popup, site doesnt seem to be using frames using Python Selenium
Cant find elements on popup, site doesnt seem to be using frames using Python Selenium

Time:10-26

I am clicking on a element that brings up a popup element, then I want to scrape data from this popup element. But I am not able to find the data or close the popup once I open it.

Looking at the element hierarchy, the popup doesn't seem to be in a different frame, but all my searching suggested that's what the problem is, so I tried below code

When I try to switch frames by element I am getting the same unable to locate element and the html data doesnt seem to show a frame related to this popup so I dont know any attributes of the frame to switch to it (I selected all frames and none of them highlighted the popup)

Here is the webpage

Clicking on "view details" under the picture shows the popup. How do I select elements on that popup?

data = []
e = driver.find_element_by_xpath(f'/html/body/div[1]/div[2]/div/div/div[5]/div[1]/div/div[4]/div/form[1]/div/div[2]/div[1]/a')
e.click() 
e =  driver.find_element_by_xpath('/html/body/div[12]/div[2]/div[4]/div/div/div/div/div[1]/div/button')  ## Shows unable to locate element error
driver.switch_to.frame(e)
    for x in range (1,5):
    element = driver.find_element_by_xpath(f'/html/body/div[13]/div[2]/div[4]/div/div/div/div/div[3]/div/div[2]/div/div[1]/ul/li[{x}]')
    data.append(element.text)  ## Doesnt have the text inside the list
    e.click()
driver.switch_to.default_content()

CodePudding user response:

The elements are not in an iframe. So no need to switch to frame. The details appear in a pop-up.

Instead of Absolute xpaths opt for Relative xpaths. Link to refer

Try like below and confirm:

# Imports required for Explicit wait:
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

driver.get("https://koa.com/campgrounds/austin-east/reserve/step2/?res=kI2O68dJS8X6si949wGzFa68NxYqwyCBul7NzF70cO3rQJLWCoDqp38g67l9SA4BcZqoRAxVFUdFtWBLcjbhl55toq-KCG20N36F-ytOHhr3EKHiJ3_qxDvkUMId1flJiRSh-9X6BDSw3EJ_IVCTNjo0ax44UscxXmfNXAVc8WybZ2xp6tu6H9lvR_igbYAXMf2t2dyN_NM-8JDDtJEe1ofkmQmsl1QJPJsZqfNq-cMnDD2mTdNCJxsfUQwEUYrUY6Q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xoVs0k0_RsiAcqaL6jEx31_shLwpGidHXgVUYrNaQ3URMf2Y_KUqB9RPIh0e8_aGoFxbthoxKQmyLMRtLutwvwmqQXx5sCEAfwQ2")

wait = WebDriverWait(driver,30)

# Options available on the page
options = driver.find_elements_by_xpath("//div[@id='reserve-container']//div[@id='site-types']")

# Get details of the 1st option.
viewdetails = options[0].find_element_by_xpath(".//div[contains(@class,'reserve-sitetype-main-row')]//a")
viewdetails.click()

# Get the heading
heading = wait.until(EC.visibility_of_element_located((By.XPATH,"//div[@class='fancybox-stage']//h3")))
print(heading.text)

# Get the details under the heading
details = driver.find_elements_by_xpath("//div[@class='fancybox-stage']//h3//parent::div//following-sibling::div//li")

for detail in details:
    print(detail.get_attribute("innerText"))

# Close the pop-up window
driver.find_element_by_xpath("//div[@class='fancybox-stage']//button[contains(@class,'wts-details-close')]").click()
AUSTIN EAST KOA HOLIDAY
6029 Blue Bluff Road Austin, TX 78724
Email: [email protected]
Reserve: 512-732-2812
Info: 800-562-8743
  • Related