dom

Detect that given element has been removed from the DOM without sacrificing performance

一个人想着一个人 提交于 2020-08-04 18:19:54
问题 I've got these: const element = this.getElementById("victim") function releaseKraken(targetElement) {} I want the function to be called when element is removed from DOM. I can imagine something like this: element.onRemove(() => releaseKraken(element)) I understand that I need MutationObserver , but all the documentation I found focuses on watching given element's children, whereas I need to watch the element itself. UPD: the question How to detect element being added/removed from dom element?

Python 3.3: Convert XML to YAML

半世苍凉 提交于 2020-08-04 14:56:16
问题 I'm trying to convert XML files to YAML using Python 3.3. This is my code: #! /etc/python3 test_filename_input = './reference-conversions/wikipedia-example.xml' test_filename_output = 'wikipedia-example_xml_read-as-binary.yaml' file_object = open( test_filename_input, 'rb') data_in = file_object.read() file_object.close() from xml.dom.minidom import parseString document_object = parseString( data_in) import yaml stream = open( test_filename_output, 'w') yaml.dump( document_object, stream)

Python 3.3: Convert XML to YAML

痞子三分冷 提交于 2020-08-04 14:53:41
问题 I'm trying to convert XML files to YAML using Python 3.3. This is my code: #! /etc/python3 test_filename_input = './reference-conversions/wikipedia-example.xml' test_filename_output = 'wikipedia-example_xml_read-as-binary.yaml' file_object = open( test_filename_input, 'rb') data_in = file_object.read() file_object.close() from xml.dom.minidom import parseString document_object = parseString( data_in) import yaml stream = open( test_filename_output, 'w') yaml.dump( document_object, stream)

Get the source (code) of an external script?

拜拜、爱过 提交于 2020-08-04 10:48:50
问题 It is possible to obtain as a string the content of an external script? Something equivalent to myInlineScript.textContent ? The scenario is that I'm just starting to get into WebGL and all the tutorials I'm finding store shaders as inline <script type="x-shader/x-foo"> tags. The element itself isn't important, however — the shaders are created from plain strings. These are easily extracted from inline scripts via .textContent , but I'd of course prefer to keep my code separate from my markup

DOMContentLoaded blocks page loading

雨燕双飞 提交于 2020-08-04 06:51:07
问题 Please, see code: <!-- ... --> <head> <style type="text/css"> body { background: gray; } </style> </head> <body> <p> Firefox does not even shows blank page. Tab is stuck in "suggested sites" for 5 seconds. </p> <p> Chrome show just blank white. No text, no background. For 5 seconds. </p> <p> DOMContentLoaded event handler blocks page loading and rendering. Browser does not start rendering page until DOMContentLoaded handler function return. </p> <script> document.addEventListener(

Getting error: “ javascript error: Cannot read property” when tracking HTML video current Time using the combination of JavaScript and Selenium

和自甴很熟 提交于 2020-07-23 07:22:20
问题 I would like in interval to track video play progress in a HTML video. Based on the tutorial, the HTML video DOM timeupdate event can be achieved by something like below: from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC import time chrome_options = webdriver.ChromeOptions() browser = webdriver.Chrome(executable_path=r"\Browsers\chromedriver.exe",

Getting error: “ javascript error: Cannot read property” when tracking HTML video current Time using the combination of JavaScript and Selenium

跟風遠走 提交于 2020-07-23 07:21:23
问题 I would like in interval to track video play progress in a HTML video. Based on the tutorial, the HTML video DOM timeupdate event can be achieved by something like below: from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC import time chrome_options = webdriver.ChromeOptions() browser = webdriver.Chrome(executable_path=r"\Browsers\chromedriver.exe",

Getting error: “ javascript error: Cannot read property” when tracking HTML video current Time using the combination of JavaScript and Selenium

北城余情 提交于 2020-07-23 07:20:15
问题 I would like in interval to track video play progress in a HTML video. Based on the tutorial, the HTML video DOM timeupdate event can be achieved by something like below: from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC import time chrome_options = webdriver.ChromeOptions() browser = webdriver.Chrome(executable_path=r"\Browsers\chromedriver.exe",

Chrome Elements console does not show unique element when given xPath

谁都会走 提交于 2020-07-22 05:48:26
问题 if I press F12 , go to Elements and click ctrl+F to search for a xPath, if I find only one element, that element is not highlighted (but Chrome will point out 1 of 1 ). If i find more than one elements, Chrome highlights from the second one. Problem occures also when I use indexes in xPath: (//a)[1] . 回答1: Seems like you are talking about this bug https://bugs.chromium.org/p/chromium/issues/detail?id=1106703 which was reported in the Chromium issue forums. It was introduced in Chrome 84 with

Object.defineProperty: setters for dom elements properties

試著忘記壹切 提交于 2020-07-21 07:18:50
问题 I can't fully understand how Object.defineProperty works on dom elements. On normal javascript objects it works like a charm var obj={name: 'john'}; Object.defineProperty(obj, 'name', { get: function(){ console.log('get value') }, set:function(newValue){ console.log('set value '+newValue); }, configurable: true }); the line obj.name='Tom'; will print to console 'set value Tom' and change obj.name to Tom. When I try it on a dom element (e.g. on the property checked of a checkbox), it will