Home > front end >  Scrapping information from the new page loaded, after button is pressed using Python selenium
Scrapping information from the new page loaded, after button is pressed using Python selenium

Time:12-07

I am trying to extract few information from the page using selenium. Initially in the first page i extracted the name. And for few fields necessary input is given in default.

Later i pressed donate button in the bottom.

Now a new page is loaded. And i need to do certain operation here. But i could not do any operations in the new page loaded.

Below the code is given till donate button is clicked, followed by code for extracting information from new page.

url = "https://donations.iskconbangalore.org/mobile-donation/?patronId=13340"
driver = webdriver.Chrome(executable_path=r'C:\Users\Admin\Downloads\chromedriver_win32\chromedriver') 
driver.get(url)

name=driver.find_element(By.ID,"donorName").get_attribute("value")
print(a)
mobile=driver.find_element(By.ID,"donorMobile").get_attribute("value")
print(mobile)


inputamt = driver.find_element(By.ID,"O5")
inputamt.send_keys('500')

inputemail = driver.find_element(By.ID,"donorEmailId")
inputemail.send_keys('[email protected]')

radioButtons = driver.find_element(By.CLASS_NAME, "custom-control-label").click()
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn order-btn2 donate-now']"))).click()

Now after the page is loaded i am trying to certain operations. But noting is happening. I wanted to scroll downn and click on the account button.

for information i have given id and class: id="account-tab-btn"

time.sleep(7)

driver.switch_to.window(driver.window_handles[0])

driver.get("https://donations.iskconbangalore.org/payment-gateway/")


# prints windows id
print(driver.window_handles)

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='account-section svelte-1mqsf83']"))).click()

CodePudding user response:

Payment-gateway page is inside an iframe, so you have to switch to that iframe, then you have to do the further actions:

After the below line:

WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn order-btn2 donate-now']"))).click()

Add this line and try:

WebDriverWait(driver, 15).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, ".razorpay-checkout-frame")))  # switch to the payment-gateway iframe

time.sleep(1)
account_link = driver.find_element(By.XPATH, ".//*[starts-with(@class,'account-tab svelte-')]//div[@data-test-id='account-tab-btn']")
driver.execute_script("arguments[0].scrollIntoView(true)", account_link)
time.sleep(1)
account_link.click()
time.sleep(1)
driver.find_element(By.XPATH, ".//*[text()='Edit contact details']").click()
  • Related