Python Selenium:Chromedriver.exe自动退出,并在if中使用函数
我在…的帮助下更改了代码。。。 当我在(“casa2_ilecell”)下添加函数test()时,进入此页面后,会弹出一个窗口,显示“chromedriver.exe自动退出”,如果单击“确认”按钮,浏览器将终止 我直接在if语句之前插入测试函数。它可以毫无疑问地工作。有什么想法吗 代码:Python Selenium:Chromedriver.exe自动退出,并在if中使用函数,python,selenium,webdriver,Python,Selenium,Webdriver,我在…的帮助下更改了代码。。。 当我在(“casa2_ilecell”)下添加函数test()时,进入此页面后,会弹出一个窗口,显示“chromedriver.exe自动退出”,如果单击“确认”按钮,浏览器将终止 我直接在if语句之前插入测试函数。它可以毫无疑问地工作。有什么想法吗 代码: 不包括驱动程序。按id(“cas2\u ilecell”)查找元素。这是不正确的语法。您只能捕获从BaseException继承的类。如果不是驱动程序,请尝试替换为。通过id(“cas2\u ilecell”
不包括驱动程序。按id(“cas2\u ilecell”)查找元素。
这是不正确的语法。您只能捕获从BaseException
继承的类。如果不是驱动程序,请尝试替换为。通过id(“cas2\u ilecell”)查找元素。
@Andersson我删除了该异常。看来这不是根本原因。。。仍然得到“chromedriver.exe”停止工作。
def test(): ##A loop to calculate the page loding time
while True:
try:
navigationStart = driver.execute_script("return window.performance.timing.navigationStart")
# domComplete = driver.execute_script("return window.performance.timing.domComplete")
loadEvent = driver.execute_script("return window.performance.timing. loadEventEnd")
onloadPerformance = loadEvent - navigationStart
time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(onloadPerformance)
driver.refresh()
except TimeoutException:
print("It took too long")
break
except not driver.find_elements_by_id("cas2_ilecell"):
print("The page does not exist")
break
# driver.quit()
u = getpass.getuser()
# # initialize Chrome options
chrome_options = Options()
# chrome_options.add_argument('--headless')
chrome_options.add_argument('user-data-dir=C:\\Users\\%s\\AppData\\Local\\Google\\Chrome\\User Data' % (u))
# chrome_driver_binary="E:\MyDownloads\Download\chromedriver.exe"
source = "https://na66.salesforce.com/5000y00001SgXm0?srPos=0&srKp=500"
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get(source)
try:
driver.find_element_by_id("Login").click()
except NoSuchElementException:
print("Don't find the login button")
#test() ##If I run the function here, and delete the bellowing code, it will be no problem
if driver.find_elements_by_id("smc"):
verificationcode()
##If the verification code is not correct()
########
WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID,"cas2_ilecell")))
test()
elif driver.find_elements_by_id("editPage"):
print("Too much")
driver.quit()
elif driver.find_elements_by_id("cas2_ilecell"):
print("Welcome")
test() **##Tried to disable the function, and it can complete the code without problem. When the function is added, even the "welcome" could not be printed.**
else:
print("Ops")
driver.quit()