Right now, my code screenshots a specific section of a webpage. However, since the element it's screenshotting is quite small on the webpage, the picture is also quite small. So, to solve this issue, I thought I could zoom into the page, center onto the element, screenshot the element, and then zoom out – but it's not working.
When I run the following code (no zooming in):
theComment = driver.find_element(By.XPATH, "/html/body/div[1]/div/div[2]/div[3]/div/div/div/div[2]/div[1]/div[2]/div[6]/div/div/div/div[1]")
driver.execute_script('arguments[0].scrollIntoView({block: "center"});', theComment)
theComment.screenshot('comment'+str(verified+1)+'.png')
I get the following image:
But when I run the following code (zooming in):
theComment = driver.find_element(By.XPATH, "/html/body/div[1]/div/div[2]/div[3]/div/div/div/div[2]/div[1]/div[2]/div[6]/div/div/div/div[1]")
driver.execute_script("document.body.style.zoom='150%'")
sleep(1)
driver.execute_script('arguments[0].scrollIntoView({block: "center"});', theComment)
sleep(1)
theComment.screenshot('comment.png')
sleep(1)
driver.execute_script("document.body.style.zoom='100%'")
I get the following image (the screenshot is really far away from where the actual comment is, and smaller than the comment is):
Any help would be greatly appreciated. Thank you.