Click on Cross Domain Iframe Element Using Rselenium

Click on cross domain iframe element using Rselenium

You can just select the first iframe and pass it to the switchToFrame method:

webElem <- remDr$findElements("css", "iframe")
remDr$switchToFrame(webElem[[1]])
webel <- remDr$findElement(using = "xpath", "//input[@id = 'TB1']")

Clicking on a custom element with Selenium (RSelenium)

If an element you wish to extract the value is in an Iframe, it needs to be switched focus first and then you can proceed to take the element by ID/Class

for example, I used to click a Button inside an Iframe from a site called "https://forexsb.com/historical-forex-data"

iframe_detect <- remDr$findElements(using = "xpath", value = "//iframe[@id='data-app-frame']")
remDr$switchToFrame(iframe_detect[[1]])
load_data_element <- remDr$findElement(using="xpath", value="//button[@id='btn-load-data']")
load_data_element$clickElement()

In above what you use of defining Class element:

down <- remDr$findElement(using="xpath", value="//mat-icon[@class='mat-icon.notranslate.icon-arrow-down-tail.mat-icon-no-color']")

I guess this is a proper full class identifier, since there is multiple name of class joint with dot operator. But in my experience, if using these can come out didn't work, I use just the first class name before the dot operator

so if I had to rewrite (note: only work if there are no more element have the same class name, or else it may take the whole element which match by the Class):

down <- remDr$findElement(using="xpath", value="//mat-icon[@class='mat-icon']")

click on iframe element using Python selenium

You need to use switch_to_frame()

driver.switch_to_frame("result")
driver.switch_to_frame(driver.find_element_by_css_selector("body>iframe"))
driver.find_element_by_css_selector("input.ex2").click()

Once you're done in the iframe, you can switch back to the top frame using:

driver.switch_to_default_content()

How to click on a link inside an iframe which is inside a frame using Selenium Webdriver and Java

I was able to get get it working by switching content by index. Using System.out.println(driver.getPageSource()); to log page source to console and make sure i am working at the right spot.
I tried to find iframes by tag and print their name as following.

List<WebElement> elements = DriverContext.driver.findElements(By.tagName("iframe"));
elements.forEach(element -> System.out.println(element.getAttribute("name"))); // printed 'menu' and 'body', perfect

But, while switching content to iframe using name, tried also using WebDriverWait,

driver.switchTo().frame(driver.findElement(By.name("menu")));

for whatever reason, it didn't work and kept throwing the exception as in the question.

Using index to switch to iframe followed by click on the element worked.

driver.switchTo().frame(0); // switch to frame
driver.switchTo().frame(0); // switch to first iframe

driver.findElement(By.id("elmt_XXXX_subMenu")).click();

Also, i had used WebDriverWait to wait for page load.

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(webDriver -> ((JavascriptExecutor) driver).executeScript("return document.readyState").toString().equals("complete"));

Python/Selenium Access element inside of iframe

You can use the below code to switch to frame and then interact with the desired element :-

wait = WebDriverWait(driver, 20)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[contains(@sandbox,'allow-popups-to-escape-sandbox')]")))
ele = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.analytics-ui-application")))
#ele is a web element so you can trigger .click, .text or any other web element methods on it.

Imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

Python selenium How to click an element in iframe?

The element you are looking after is inside nested iframe. You need to switch both the
iframes.

Use following css selector to identify the iframe.

WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name='landingpage']"))) 
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src*='plus.web.de']")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "save-all-conditionally"))).click()

Or Use below xpath to identify the iframe.

WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@name='landingpage']"))) 
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[contains(@src,'plus.web.de')]")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "save-all-conditionally"))).click()

RSelenium findElement function

The data you want to scrape is in iframe.

Sample Image

One way to do is,

remDr$navigate('https://csi2.valutrades.com/sentimentgraph.php')
webElem <- remDr$findElement('xpath', '//*[@id="EURUSD"]')
webElem$getElementText()
[[1]]
[1] "EURUSDLongShort44.3%55.7%"


Related Topics



Leave a reply



Submit