-2

I want to run some query on here

from time import sleep
    
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
    
driver.get("https://www.scribbr.com/paraphrasing-tool/")
    
WebDriverWait(driver, 30).until(
    EC.visibility_of_element_located((By.TAG_NAME, "iframe")))
frames = driver.find_elements(by=By.TAG_NAME, value='iframe')
for f in frames:
    print("Frame src: ", f.get_attribute('src'))
# Frame src:  https://quillbot.scribbr.com/? 
  # independentTool=true&language=EN&partnerCompany=scribbr.com
# Frame src:  
# Frame src:  https://consentcdn.cookiebot.com/sdk/bc-v4.min.html

driver.switch_to.frame(0)

print(driver.page_source)
# '<html><head></head><body></body></html>' !!!!


input_text_area = driver.find_element(By.ID, 'paraphraser-input-box') # `NoSuchElementException`
LearnToGrow
  • 1,656
  • 6
  • 30
  • 53

2 Answers2

-1

The desired element is within an <iframe> so you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.

  • Induce WebDriverWait for the desired element to be clickable.

  • You can use either of the following locator strategies:

    driver.get("https://www.scribbr.com/paraphrasing-tool/")
    WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#ifrm")))
    driver.execute_script("arguments[0].textContent = arguments[1]", WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div#paraphraser-input-box"))), "multi-task")
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
-1

You have to add some wait time to handle the iframe, because without wait time it's not working all the time, try the below code:

heading = driver.find_element(By.CSS_SELECTOR, ".d-inline-block h1")
driver.execute_script("arguments[0].scrollIntoView(true)", heading)
time.sleep(1)
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.ID, "ifrm")))
time.sleep(1)
driver.find_element(By.ID, "paraphraser-input-box").send_keys("multi-task")
time.sleep(1)
driver.find_element(By.CSS_SELECTOR, ".MuiButton-root").click()
AbiSaran
  • 2,538
  • 3
  • 9
  • 15
  • did you test the code on your side ? It triggers a `NoSuchElementException` on line 6 – LearnToGrow Jan 24 '23 at 14:15
  • I tested the code several times, it is working fine, what is the intention of your question? – AbiSaran Jan 24 '23 at 15:32
  • for a list of text =['text1', 'text2', ..], I want to rephrase each one several time (I did only one in the code) and then save the result in a dict. {'text1': ['phrase1', 'phrase2'], 'text2':[...]}. Your code does not work on my machine. I edit my code above and when I switch to the frame and print the `page_source`, it looks empty – LearnToGrow Jan 24 '23 at 15:37
  • You changed your question now. First you asked a different question, for that I answered, it is working fine. Now you changed the question and asking that my answer is not working. – AbiSaran Jan 24 '23 at 15:41
  • Well, thanks for your answer but the question is the same, maybe your solution is running fine on your machine but not on my machine. It is simple! Which version of selenium and driver do you use ? – LearnToGrow Jan 24 '23 at 15:44