vchrome 0.0.1__py3-none-any.whl → 0.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
vchrome/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = '0.0.1'
1
+ __version__ = '0.0.3'
2
2
  __author__ = 'v'
3
3
  # ----------------------------------------------------------------------------------------------------
4
4
  _allowed = {'Chrome'}
@@ -1198,6 +1198,16 @@ def cdp_client(hostname, port, debug=False):
1198
1198
  return self.f.element.visibility(self.objectId)
1199
1199
  def visible(self):
1200
1200
  d = self._view_info()
1201
+ # Page navigation destroys frames, invalidating the objectId's execution context and necessitating reacquisition.
1202
+ # only for ele(). on all need run wait_show() functions.
1203
+ if d.get('code') == -32000:
1204
+ f = getattr(self, 're_search', None)
1205
+ if f:
1206
+ e = f()
1207
+ if e:
1208
+ self.className = e.className
1209
+ self.objectId = e.objectId
1210
+ d = self._view_info()
1201
1211
  d['isCoverd'] = self._is_coverd()
1202
1212
  return d
1203
1213
  def info(self):
@@ -1254,6 +1264,7 @@ def cdp_client(hostname, port, debug=False):
1254
1264
  self.f = f
1255
1265
  self.attach(f)
1256
1266
  def attach(self, f):
1267
+ f.id = self.id
1257
1268
  f.ele = self.ele
1258
1269
  f.eles = self.eles
1259
1270
  f.xpath = self.xpath
@@ -1295,6 +1306,8 @@ def cdp_client(hostname, port, debug=False):
1295
1306
  if one and r: return r
1296
1307
  r.extend(sr.css(xf))
1297
1308
  return r
1309
+ def id(self, x, timeout=8, no_wait=False, all_frames=True):
1310
+ return self.ele('#'+ x, timeout=timeout, no_wait=no_wait, all_frames=all_frames)
1298
1311
  def ele(self, x, timeout=8, no_wait=False, all_frames=True):
1299
1312
  start = perf_counter()
1300
1313
  over_v_time = 2
@@ -1304,7 +1317,9 @@ def cdp_client(hostname, port, debug=False):
1304
1317
  if ctime - start > over_v_time: over_v_limit = True
1305
1318
  r = self._parse_x(x, all_frames, one=True, over_v_limit=over_v_limit)
1306
1319
  if ctime - start > over_v_time: over_v_limit = False
1307
- if r: return r[0]
1320
+ if r:
1321
+ r[0].re_search = lambda:self.ele(x)
1322
+ return r[0]
1308
1323
  if no_wait: return None
1309
1324
  if ctime - start > timeout:
1310
1325
  raise Exception('ele selecter timeout.')
@@ -1363,9 +1378,19 @@ def cdp_client(hostname, port, debug=False):
1363
1378
  _trav(snode)
1364
1379
  _trav(rnode)
1365
1380
  return clist
1381
+ def _get_doc_tree(self):
1382
+ start = perf_counter()
1383
+ while True:
1384
+ doc = self.f.cdp('DOM.getDocument', {'depth':-1, 'pierce':True})
1385
+ if 'root' in doc:
1386
+ return doc
1387
+ else:
1388
+ time.sleep(0.1)
1389
+ if perf_counter() - start > 2:
1390
+ break
1366
1391
  def _get_flattened_node(self, nodeId=None):
1367
1392
  if nodeId == None:
1368
- rnode = self.f.cdp('DOM.getDocument', {'depth':-1, 'pierce':True})['root']
1393
+ rnode = self._get_doc_tree()['root']
1369
1394
  else:
1370
1395
  rnode = self.f.cdp('DOM.describeNode', {'nodeId':nodeId, 'depth':-1, 'pierce':True})['node']
1371
1396
  mnodes = {"nodes": self._trav_node_tree(rnode)}
@@ -1928,8 +1953,6 @@ def cdp_client(hostname, port, debug=False):
1928
1953
  self.element = ElementTools(self)
1929
1954
  self.browser = Browser(self)
1930
1955
  self.keyboard = Keyboard(self)
1931
- def id(self, i):
1932
- return self.ele('#'+ i)
1933
1956
  def press(self, key): self.cdp('Input.dispatchKeyEvent', self.keyboard._make_down(key))
1934
1957
  def release(self, key): self.cdp('Input.dispatchKeyEvent', self.keyboard._make_up(key))
1935
1958
  def close(self):
@@ -1,3 +1,3 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vchrome
3
- Version: 0.0.1
3
+ Version: 0.0.3
@@ -0,0 +1,5 @@
1
+ vchrome/__init__.py,sha256=EJQjfA2gVhXOHKjJATTFr9ePDw-THC4DTMflWnAitck,206316
2
+ vchrome-0.0.3.dist-info/METADATA,sha256=AFIZUSrXsfq6ga97ItMe7CSflB5qxy28d0Di9Zqkhvc,54
3
+ vchrome-0.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
4
+ vchrome-0.0.3.dist-info/top_level.txt,sha256=oB919Fa09PCy48Ptj8iy-1QUcvhEeY97MOR42281Fk0,8
5
+ vchrome-0.0.3.dist-info/RECORD,,
@@ -1,5 +0,0 @@
1
- vchrome/__init__.py,sha256=3hGkPIEIEqdztxgUv_xzCfSh94LydiST-h0aRbbKcFo,205275
2
- vchrome-0.0.1.dist-info/METADATA,sha256=sYEl8TU0KeoZfxt5CiNQCP9kl_jR6ztqpO9cHeOQzfk,54
3
- vchrome-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
4
- vchrome-0.0.1.dist-info/top_level.txt,sha256=oB919Fa09PCy48Ptj8iy-1QUcvhEeY97MOR42281Fk0,8
5
- vchrome-0.0.1.dist-info/RECORD,,