Closed kieranperk closed 1 year ago
what browser do you use? do you use adblocker at all?
You can use the click() method of the WebElement class within selenium. You will just need to find the element.
@kieranperk One method you could try is by clicking the element that contains the text 'Accept all'. It is a lot easier than getting the ID of the element. Below is an example but it does slow the process down. By all means you could try another approach but this one seemed to work for me, it doesn't work all the time and has its issues.
# screenshot.py
def getPostScreenshots(filePrefix, script):
print("Taking screenshots...")
driver, wait = __setupDriver(script.url)
script.titleSCFile = __takeScreenshot(filePrefix, driver, wait)
for commentFrame in script.frames:
try:
button = wait.until(EC.element_to_be_clickable((By.XPATH, "//*[contains(text(),'Accept all')]")))
button.click()
except:
pass
commentFrame.screenShotFile = __takeScreenshot(filePrefix, driver, wait, f"t1_{commentFrame.commentId}")
driver.quit()
@kieranperk One method you could try is by clicking the element that contains the text 'Accept all'. It is a lot easier than getting the ID of the element. Below is an example but it does slow the process down. By all means you could try another approach but this one seemed to work for me, it doesn't work all the time and has its issues.
# screenshot.py def getPostScreenshots(filePrefix, script): print("Taking screenshots...") driver, wait = __setupDriver(script.url) script.titleSCFile = __takeScreenshot(filePrefix, driver, wait) for commentFrame in script.frames: try: button = wait.until(EC.element_to_be_clickable((By.XPATH, "//*[contains(text(),'Accept all')]"))) button.click() except: pass commentFrame.screenShotFile = __takeScreenshot(filePrefix, driver, wait, f"t1_{commentFrame.commentId}") driver.quit()
@ItsLeon15 Thank you very much! I added the code to the __setupDriver() function so it ran asap and only once and it seems to work really well!
def __setupDriver(url: str):
options = webdriver.FirefoxOptions()
options.headless = False
options.enable_mobile = False
driver = webdriver.Firefox(options=options)
wait = WebDriverWait(driver, 10)
driver.set_window_size(width=screenWidth, height=screenHeight)
driver.get(url)
try:
button = wait.until(EC.element_to_be_clickable((By.XPATH, "//*[contains(text(),'Accept all')]")))
button.click()
except:
print("No 'Accept all' button found on the page")
I've managed to get my system all working, however whenever it goes to take screenshots I have to quickly manually click the cookie accept button every single time I want to create a video which can get tricky when it only gives you like a second until it starts to take all of the screenshots. Any ideas on what I could do?
Example of the screenshots it gives me: