IFrame Alpha

This commit is contained in:
NaiboWang-Alienware
2023-07-04 22:57:33 +08:00
parent 11cda1bc1f
commit 316686e416
5 changed files with 11 additions and 16 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -10,7 +10,7 @@
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"args": ["--id", "[29]", "--read_type", "remote", "--headless", "0"]
"args": ["--id", "[38]", "--read_type", "remote", "--headless", "0"]
// "args": ["--id", "[2]", "--read_type", "remote", "--headless", "0", "--saved_file_name", "YOUTUBE"]
// "args": ["--id", "[44]", "--headless", "0", "--user_data", "1"]
}
-6
View File
@@ -465,8 +465,6 @@ class BrowserThread(Thread):
'return history.length') # 记录本次循环内的history的length
self.history["index"] = thisHistoryLength
self.history["handle"] = thisHandle
# if node["parameters"]["iframe"]:
# self.browser.switch_to.default_content() # 循环前切换到主文档
if int(node["parameters"]["loopType"]) == 0: # 单个元素循环
# 无跳转标签页操作
count = 0 # 执行次数
@@ -651,8 +649,6 @@ class BrowserThread(Thread):
self.executeNode(i, code, node["parameters"]["xpath"], 0)
self.history["index"] = thisHistoryLength
self.history["handle"] = self.browser.current_window_handle
# if node["parameters"]["iframe"]:
# self.browser.switch_to.default_content()
self.scrollDown(node["parameters"])
# 打开网页事件
@@ -840,8 +836,6 @@ class BrowserThread(Thread):
self.recordLog("Cannot find element:" +
path + ", please try to set the wait time before executing this operation")
print("找不到要点击的元素:" + path + ",请尝试在执行此操作前设置等待时间")
# if para["iframe"]:
# self.browser.switch_to.default_content()
waitTime = float(para["wait"]) + 0.01 # 点击之后等待
try:
waitType = int(para["waitType"])
+8 -8
View File
@@ -32,13 +32,14 @@ class MyChrome(webdriver.Chrome):
if iframe:
# 获取所有的 iframe
try:
iframes = super().find_elements(By.XPATH, "//iframe")
iframes = super().find_elements(By.CSS_SELECTOR, "iframe")
except Exception as e:
print(e)
find_element = False
# 遍历所有的 iframe 并点击里面的元素
for iframe in iframes:
# 切换到 iframe
super().switch_to.default_content()
super().switch_to.frame(iframe)
self.iframe_env = True
try:
@@ -64,20 +65,19 @@ class MyChrome(webdriver.Chrome):
# 在这里改变查找元素的行为
if iframe:
# 获取所有的 iframe
iframes = iframes = super().find_elements(By.CSS_SELECTOR, "iframe")
iframes = super().find_elements(By.CSS_SELECTOR, "iframe")
find_element = False
# 遍历所有的 iframe 并点击里面的元素
for iframe in iframes:
# 切换到 iframe
super().switch_to.default_content()
super().switch_to.frame(iframe)
self.iframe_env = True
try:
# 在 iframe 中查找并点击元素
# 在这个例子中,我们查找 XPath 为 '//div[1]' 的元素
elements = super().find_elements(by=by, value=value)
# 在 iframe 中查找并点击元素
# 在这个例子中,我们查找 XPath 为 '//div[1]' 的元素
elements = super().find_elements(by=by, value=value)
if len(elements) > 0:
find_element = True
except NoSuchElementException:
print("No such element found in the iframe")
# 完成操作后切回主文档
# super().switch_to.default_content()
if find_element: