首页 > 解决方案 > 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)

但是没有更新!!?

标签: pythonseleniumselenium-webdriver

解决方案


推荐阅读