PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 15, 2022

[FIXED] How to click a box with selenium which i can't see its element?

 April 15, 2022     iframe, pandas, python, screen-scraping, selenium     No comments   

Issue

I want to change the frametime in fxblue technical analysis from 1h (the default value) to 5m but i can't click its pop-up button. here is the code i tried:

import pandas as pd
import numpy as np
import csv
import os
from selenium import webdriver
driver = webdriver.Chrome(os.getcwd() + '/chromedriver')  
url = "https://www.fxblue.com/market-data/technical-analysis/EURUSD"
driver.get(url)
time.sleep(5)
timestamp = driver.find_element_by_xpath('//*[@id="TimeframeContainer"]').click()

at this point I can see the pop-up with the timeframes but I couldn't find a way to change the timeframe.


Solution

The elements in the Timeframe pop-up is in an iframe. Need to switch to frame to interact with the elements contained in it.

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

driver.get("https://www.fxblue.com/market-data/technical-analysis/EURUSD")

wait = WebDriverWait(driver,30)

# Click on timestamp button.
timestamp = wait.until(EC.element_to_be_clickable((By.ID,"txtTimeframe")))
timestamp.click()

# Switch to iframe.
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[contains(@class,'DialogInnerIframe')]")))

# click on M5 button.
fivemin = wait.until(EC.element_to_be_clickable((By.XPATH,"//div[@class='TimeframeItem' and text()='M5']")))
fivemin.click()

# Switch to default content to interact with other elements.
driver.switch_to.default_content()


Answered By - pmadhu
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing