After clicking this button via. selenium, the button starts loading as shown. The site is
This is the button HTML code :
<button class="MuiButtonBase-root MuiButton-root MuiButton-contained QuillButton-sc-12j9igu-0 dkavuo quillArticleBtn jss1419 MuiButton-containedPrimary" tabindex="0" type="button"><span class="MuiButton-label"><div class="jss1421">Paraphrase</div><div class="jss1425" style="opacity: 0; transition: opacity 1100ms cubic-bezier(0.4, 0, 0.2, 1) 0ms; visibility: hidden;"></div></span></button>
After the loading/processing, the button is changed back to its normal state.
I know, this is something to do with JavaScript, how can I know when the button is finished loading ? I am basically trying to automate the entire process
CodePudding user response:
You can do it without use of JavaScript or any additional to Selenium tools and skills.
The "Rephrase" button itself classes are changing between the states.
While the rephrasing process the button element contains several additional class names. One of them isMui-disabled
. So to indicate the rephrasing process is complete / not running now you can validate as following:self.wait.until(EC.presence_of_element_located((By.XPATH, "//button[contains(@class,'QuillButton') and(not(contains(@class,'Mui-disabled')))]")))
CodePudding user response:
So basically when you get to the site you send the keys to the div tag. Click the rephrase button and then wait for the element to come back. I just used time to check if there was any difference on the load.
wait=WebDriverWait(driver, 60) driver.get('https://quillbot.com/') wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#inputText"))).send_keys("This is a test") wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#InputBottomQuillControl > div > div > div > div:nth-child(2) > div > div > div > div > button"))).click() print(time.perf_counter()) wait.until(EC.presence_of_element_located((By.XPATH,"//div[@style='opacity: 0; transition: opacity 1100ms cubic-bezier(0.4, 0, 0.2, 1) 0ms; visibility: hidden;']"))) print(time.perf_counter())
Import
from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import time