scob_
scob_

Reputation: 287

Can't click element by xpath inside iFrame - Selenium

I'm aware that I have to switch to an iframe when I want to click and element inside it. Heres what the start of the iFrame looks like:

<iframe src="about:blank" name="tool_content" id="tool_content" class="tool_launch" allowfullscreen="allowfullscreen" webkitallowfullscreen="true" mozallowfullscreen="true" tabindex="0" title="Tool Content" style="height: 100%; width: 100%;" allow="geolocation *; microphone *; camera *; midi *; encrypted-media *; autoplay *" data-lti-launch="true"></iframe>

I switched to it using driver.switch_to.frame(driver.find_element_by_class_name("tool_launch"))

I then tried clicking a 'Join' button inside the Iframe by using it's exact xpath:

driver.find_element_by_xpath("/html/body/div[1]/div/div/div[2]/div/div/div[3]/div[1]/div[2]/div/div/div/div/div/div/div/div/div/div/table/tbody/tr/td[4]/div/div[1]/a").click()

But it keeps saying it's not present. Why? There are no further iframes inside that one, and this xpath is completely 100% inside the iframe. It can recognise other elements, so why not this one?

Here's the join button element line:

<a target="_blank" href="/lti/rich/j/96494344321?oauth_consumer_key=AAPUZMZcQCSN85nnG74vOQ&amp;lti_scid=ee49a632bee823b3046456c29c5eb4064ee1e3790f433af82bebaf2752bde531" class="ant-btn ant-table-span" style=""> Join</a>



Heres what the iframe looks like - I want to click the join button: enter image description here

It's inside a table.

I'm able to select things like the 'previous meetings' tab, but cannot use the Join or invitation buttons.

Here is the full HTML

I cannot paste it because this can only be viewed in inspect element (when viewing the source, you can't see all this), and I would only be able to copy one element at a time.

I have highlighted at the top where the start of the iframe is, and where the Join button that I want to click is.

The two images just continue on from one another.

enter image description here

enter image description here

Edit #1

I tried using the css selector - same result.

Upvotes: 0

Views: 1093

Answers (1)

Arundeep Chohan
Arundeep Chohan

Reputation: 9969

Try waiting and clicking on the element. Try not to use xpath.

elem=WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.ant-btn.ant-table-span")))
elem.click()

Import

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

Upvotes: 2

Related Questions