python - google colab 仍然没有变化:python 中的 selenium
问题描述
import time
import sys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver=webdriver.Chrome('chromedriver',options=options)
driver.get("https://rentry.co/wftw8/edit")
driver.implicitly_wait(20)
#print (driver.page_source)
try:
# here I selected the **span** element that I talk above
span = driver.find_element_by_xpath('//*[@id="text"]/div/div[5]/div[1]/div/div/div/div[5]/pre/span')
# change the innerText thwough js
driver.execute_script('arguments[0].innerText="Hello boy"', span)
# just wait for the id_edit_code to be present
edit = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "id_edit_code")))
edit.send_keys("iRfiNq6M")
# and same as you had it
#driver.find_element_by_id("submitButton").send_keys(Keys.ENTER)
#driver.find_element_by_link_text("Save").click()
driver.find_element_by_id("submitButton").click()
except:
print("Oops!", sys.exc_info()[0], "occurred.")
finally:
driver.close()
print("done")
也不例外,但文本的更新仍然没有反映在 url 中?
即使有足够的计时器来处理整个代码。然后也没有更新。
目前,如果您访问 URL ,文本是Hello ,但我希望它是使用 selenium 的Hello boy,这是通过以下代码行完成的:
span = driver.find_element_by_xpath('//*[@id="text"]/div/div[5]/div[1]/div/div/div/div[5]/pre/span')
# change the innerText thwough js
driver.execute_script('arguments[0].innerText="Hello boy"', span)
但是没有更新!!?
解决方案
推荐阅读
- javascript - 你如何通过反应和本地存储将数据保持在状态?
- reactjs - useState 未使用 socket.io 正确更新
- bazel - Bazel:将 Linux 远程执行平台与 Mac OS 本地平台混合
- c++ - Uno 的卡片类向量
- javascript - Firebase 身份验证检测用户是否来自重定向登录
- javascript - 如何从最大化 RAM 修复浏览器 blob 下载?
- curl - 我可以将笑话代码覆盖率添加到来自管道的 Bitbucket 拉取请求中的报告吗
- python - 如何从不同的内联查询中获取不同的 cache_times?
- c - 使用 C 将浮点数拆分为分数和积分
- firebase - 在 Android 上使用 Unity 中的 Firebase 登录 Apple 会引发“客户端与 api 密钥不匹配”异常