在iframe硒中找不到元素

时间:2019-03-17 23:34:13

标签: python selenium

我正在尝试切换到网页上的框架以访问该框架中的视频,但是始终会出现错误,即找不到元素,而我尝试了很多元素都出错

这是我用来切换到框架并获取视频网址的代码

WebDriverWait(browser,10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//*[@id = 'innerframe']/iframe")))

browser.find_element_by_xpath("//video[@id='mediaplayer']/soucre").text

这是页面HTML PAGE的html

        <div id="innerframe"><iframe src="https://ops.cielo24.com/hitman/work/load_task/554097cdbe314edb9ad5d62edf5396ed/tasks/2547efb19fc5430c9f335fe165a46df3?active_task_uuid=44686eab1ad8448d97e5e74e484575ab" width="100%" height="100%" frameborder="0"></iframe>

视频html:

<div id="mediacontent">
    <video height="305" width="480" id="mediaplayer"><source src="https://c24cdn.co/restricted/sliced-media/790f319ee29c46e585c5ee585ed31580.mp4?Expires=1584401901&amp;GoogleAccessId=microservice-writer%40coresystem-171219.iam.gserviceaccount.com&amp;Signature=QtSAPQc5GMxPx9qAI8WnCurouFagNgRE2rto1B3af%2BrUhemeqoFnJZWmfQfQ2SGXKAhc5pXL68GhLINlshZ4yGEvy7SDMEr1l44Z%2FA9bFL3Xvlsii9MfZpkXaCeXT%2FKrMZZvH%2BpbiR%2BpgQjgqLysP68fODMsQ3zub9FCx8zD2Yw5bQZg12rzQWdlEcU5VHGktTSDAjpReWHIrmca63X6jQAYru5TQi12sy18UwSlpdrF1qFgXlTOEMKwB2iPHbLRPxxpFF%2FhOkYVrCcIi6OmJOXvy6arBZY9%2FYBP2vjIpDQ3UODyH8uFrEFdWbqVTHAe0G0pKly4NK1K30dKrSGYJw%3D%3D" type="video/mp4"><source src="https://c24cdn.co/restricted/sliced-media/59b2c60d2e764a25bd4a8e2d6f15cb31.webm?Expires=1584401901&amp;GoogleAccessId=microservice-writer%40coresystem-171219.iam.gserviceaccount.com&amp;Signature=JGbxZYS0u2rI2gY%2BjXThKj9KkIMBDfLvW9XEImWdtfzMFNpUBBm33B7wM3XYD01JLKcMD%2BlqfWf%2FqzMFAgW2zQH07NvGKzdkYFIgwxgCUQha8ws%2FLqoJyLMiz8UeXr5Smqqjr%2FiFrLLc6HmCnYfP8g7Y%2BJ%2FJoQuHmVeZjJIKxz957SZEOQ8QIQqtbIusK%2B0uqQzvyyW4vStDF7RvjZwp44b1H0pqzsby2bjCYspacgv9JM712Z72sZdercFFczC5BR%2FxT0jXFxYn6XiRhfE0HO1e24qFiR1A%2B78Ems3A3ZdQylaVDZ4UfVX13iofy2l0LWdXMjEynLxSz7cNPGtDpg%3D%3D" type="video/webm"></video>
</div>

1 个答案:

答案 0 :(得分:0)

您使用的xpath不正确,因为其中存在键入错误,您使用的是from selenium.webdriver.common.action_chains import ActionChains for i in range(3000): #scroll 3000 times ActionChains(driver).send_keys(Keys.END).perform() 而不是soucre,并且用来获取它的结构也不正确。
因此,尝试使用下面的代码,它应该可以正常工作。

source