浏览器 window 打开 URL 然后在 Selenium Python 中突然关闭
Browser window open the URL then suddenly closes in Selenium Python
问题是当浏览器 window 打开 Facebook 页面时,我希望它点击创建新帐户。
我使用的用于创建新帐户的 XPATH 是
//a[text()='Create New Account']
但它打开 facebook.com 然后突然关闭,尽管我有其他脚本可以正常工作。
完整代码:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait as Wait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.get("https://facebook.com")
link_locator = '//a[text()="Create New Account"]'
create_account = Wait(driver, 5).until(EC.presence_of_element_located((By.XPATH, link_locator))).click()
浏览器已立即关闭,因为只有命令点击,驱动程序成功了,由于接下来没有任何事情,关闭了驱动程序。
尝试在末尾添加time.sleep(10),你会看到出现注册弹窗:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait as Wait
from selenium.webdriver.support import expected_conditions as EC
import time
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.get("https://facebook.com")
link_locator = '//a[text()="Create New Account"]'
create_account = Wait(driver, 5).until(EC.presence_of_element_located((By.XPATH, link_locator))).click()
time.sleep(10)
driver.quit()
问题是当浏览器 window 打开 Facebook 页面时,我希望它点击创建新帐户。 我使用的用于创建新帐户的 XPATH 是
//a[text()='Create New Account']
但它打开 facebook.com 然后突然关闭,尽管我有其他脚本可以正常工作。
完整代码:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait as Wait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.get("https://facebook.com")
link_locator = '//a[text()="Create New Account"]'
create_account = Wait(driver, 5).until(EC.presence_of_element_located((By.XPATH, link_locator))).click()
浏览器已立即关闭,因为只有命令点击,驱动程序成功了,由于接下来没有任何事情,关闭了驱动程序。
尝试在末尾添加time.sleep(10),你会看到出现注册弹窗:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait as Wait
from selenium.webdriver.support import expected_conditions as EC
import time
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.get("https://facebook.com")
link_locator = '//a[text()="Create New Account"]'
create_account = Wait(driver, 5).until(EC.presence_of_element_located((By.XPATH, link_locator))).click()
time.sleep(10)
driver.quit()