GithubHelp home page GithubHelp logo

Cannot get element inside Iframe. about rod HOT 11 CLOSED

alufrew avatar alufrew commented on August 18, 2024
Cannot get element inside Iframe.

from rod.

Comments (11)

ysmood avatar ysmood commented on August 18, 2024

Usually, you just use document.querySelector("#iframe_selector") directly on the devtools console to debug. I think you won't be able to find it in the browser either.

I see people encounter similar issues all the time. Such as when an iframe is inside another iframe you need to call Frame() for each level. Such as query shadow DOM elements, you have to use special js to handle them, etc.

If you can provide me the page I can help you to figure out the problem. If I can't reproduce your issue I'm afraid that I can't do much about it.

Here the example of nested iframes: https://github.com/ysmood/rod/blob/a072993e8f2e5b768bf92f5a517a7fca21a3e2ce/element_test.go#L36

from rod.

alufrew avatar alufrew commented on August 18, 2024

Hm. document.querySelector("#iframe_selector") finds element under iframe context (if you select it in console manually). Can I get current iFrame name when I switched to it?

from rod.

ysmood avatar ysmood commented on August 18, 2024

Can you do something like this for me?

Screen Shot 2020-04-23 at 0 22 48

from rod.

ysmood avatar ysmood commented on August 18, 2024

To get the details about the iframe you can just do something like this

fmt.Println(fr.Element("#element_selector").Describe())

Make sure the src is the one you want.

from rod.

alufrew avatar alufrew commented on August 18, 2024

from rod.

ysmood avatar ysmood commented on August 18, 2024

You sure it's not nested iframes and not shadow dom?

from rod.

alufrew avatar alufrew commented on August 18, 2024

from rod.

ysmood avatar ysmood commented on August 18, 2024

Rod is designed to prevent the use of time.Sleep. You can use WaitInvisible, WaitStable instead, here the example code:

package main

import (
	"github.com/ysmood/kit"
	"github.com/ysmood/rod"
	"github.com/ysmood/rod/lib/launcher"
)

func main() {
	url := launcher.New().
		Headless(false). // run chrome on foreground
		Launch()

	browser := rod.New().ControlURL(url).Connect()
	defer browser.Close()

	page := browser.Page("https://buynow.account.sz.clario.co/lumis_fastspring_bn_emulator_with_login.html")

	page.Element("#login_email").Input("[email protected]")
	page.Element("#login_submit").Click().WaitInvisible()
	page.ElementX("//p/button[@data-fsc-item-path='test-clario-1mo']").Click()

	fr := page.Element("#fsc-popup-frame").Frame()

	fr.Element("#contact-last-name").WaitStable().Click()

	kit.Pause()
}

from rod.

ysmood avatar ysmood commented on August 18, 2024

The issue is caused by site-per-process, you can use the rod v0.25.7 to overcome it.

I thought I don't need site-per-process anymore but seems like we still have to keep it, hope in the future chrome can expose a special API for iframe to handle js injection.

from rod.

alufrew avatar alufrew commented on August 18, 2024

Thank you for fix. It's working now. I used time.Sleep just to make sure that framework doen't hang before iFrame is loaded. It wont be used in actual code.

from rod.

ysmood avatar ysmood commented on August 18, 2024

Good to hear that 👍

from rod.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.