Basically, I’m trying to get the program to find the keyword, and if it manages to do it, it will click the link to the pdf file in the page (for now i just want to print a confirmation message)
But, despite the keyword clearly being in the page, selenium can’t manage to find it.
Here’s the block of code:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
url = 'https://www.bursamalaysia.com/market_information/announcements/company_announcement/announcement_details?ann_id=3434107'
driver.get(url)
try:
WebDriverWait(driver, 10).until(EC.text_to_be_present_in_element((By.TAG_NAME, "body"), "Annual Audited Accounts"))
print("Found: Annual Audited Accounts")
except:
print("Text not found")
driver.quit()
I’ve tried all sorts of search methods, including XPath and JavaScript, but I literally can’t search for it.
I’m currently using Selenium on PyCharm fyi
2
Answers
It’s Because the keyword Annual Audited Accounts is part of an iframe which selenium cannot access directly, you need to first switch to the iframe
add below code to swtich to ifrma first driver.switch_to.frame(driver.find_element(By.NAME,’announcement_detail_iframe’))
Full Code
Prints
You just need to handle the IFRAMES
Check the working code below:
Result: