Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 屏幕截图中没有交互元素_Python_Selenium_Selenium Webdriver_Phantomjs_Screenshot - Fatal编程技术网

Python 屏幕截图中没有交互元素

Python 屏幕截图中没有交互元素,python,selenium,selenium-webdriver,phantomjs,screenshot,Python,Selenium,Selenium Webdriver,Phantomjs,Screenshot,我正在使用以下代码进行屏幕截图: from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities dcap = dict(DesiredCapabilities.PHANTOMJS) dcap["phantomjs.page.settings.userAgent"] = ('Mozilla/5.0 (Windows NT 6.1) Appl

我正在使用以下代码进行屏幕截图:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = ('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36')
driver = webdriver.PhantomJS(desired_capabilities=dcap,service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any','--web-security=false']) 
driver.set_window_size(1920, 1080)
driver.get("https://app.wisemapping.com/c/maps/579829/public")
driver.save_screenshot('screen.png')
driver.quit()
我得到的只是:

如果你去我做这件事的地方,你会看到思维导图。
我不知道是什么问题,我试过chromedriver,一切都一样,但是在其他网站上一切都很好。

你需要添加一个webdriver等待,以便元素出现在屏幕上,然后拍摄屏幕截图

WebDriverWait(driver,10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#workspace > g:nth-child(3) > rect:nth-child(2)")))
这些是你需要的进口货

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
在截图之前添加这一行

WebDriverWait(driver,10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#workspace > g:nth-child(3) > rect:nth-child(2)")))
张贴您将看到正确的屏幕截图
这是一个时间问题。屏幕截图是在加载元素并使其可见之前拍摄的。使用显式等待来等待它们

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

driver.get("https://app.wisemapping.com/c/maps/579829/public")

WebDriverWait(driver, 10).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "#workspaceContainer > svg > [preserveAspectRatio]")))

driver.save_screenshot('screen.png')

错误,我尝试了更多的时间,仍然不起作用<代码>回溯(最后一次调用):文件“C:\…\”,第13行,在WebDriverWait(驱动程序,10)中。直到(EC.presence\u of_element位于((By.CSS\u SELECTOR,“\workspace>g:nth child(3)>rect:nth child(2)”)文件“C:\Program Files\Python36\lib\site packages\selenium\webdriver\support\wait.py),第80行,直到引发TimeoutException(消息、屏幕、堆栈跟踪)selenium.common.exceptions.TimeoutException:Message:Screenshot:available via screen你能试试Chromedriver的代码吗,看看它是否有效,在我寻找PhantomJS issueOk的同时,我试过Chromedriver,现在它有效了,出于某种原因,我猜PhantomJS在该网站上不能正常工作。使用Pha时我也看到了错误ntomJS,我会在找到任何解决方案时通知你