我在MS Edge上进行自动化测试,我无法将密钥发送到本地网站的文本字段。
我正在使用Python 2.7和适当版本的MicrosoftWebDriver。
import time
from selenium import webdriver
import string
import unittest
import random
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from random import choice
from string import ascii_uppercase
from selenium.webdriver.support.ui import Select
import time
import json
import sys
def runtest():
driver.set_window_size(1280, 900)
driver.get("http://localhost/project/interio/interio/");
time.sleep(1) # Let the user actually see something!
loginfinal = driver.find_element_by_xpath("//a[@href='AdminLogInFinal.php']") #for login
loginfinal.click()
Login_name= driver.find_element_by_name('user')
Login_name.send_keys('09')
test6 = Login_name.get_attribute('value')#.encode('utf-8')
print test6
Login_password= driver.find_element_by_name('pass')
Login_password.send_keys('se')
test7 = Login_password.get_attribute('value')#.encode('utf-8')
print test7
driver.quit()
driver = webdriver.Edge("MicrosoftWebDriver.exe")
runtest()
错误:Edge不执行发送密钥
C:\python code>python localwebsitetest.py
Traceback (most recent call last):
File "localwebsitetest.py", line 36, in <module>
runtest()
File "localwebsitetest.py", line 23, in runtest
Login_name= driver.find_element_by_name('user')
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 365, in find_element_by_name
return self.find_element(by=By.NAME, value=name)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 752, in find_element
'value': value})['value']
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: No such element
我尝试过只按ID查找元素,但它不起作用。
这是我的代码
import time
from selenium import webdriver
import string
import unittest
import random
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from random import choice
from string import ascii_uppercase
from selenium.webdriver.support.ui import Select
import time
import json
import sys
def runtest():
driver.set_window_size(1280, 900)
driver.get("http://localhost/project/interio/interio/");
time.sleep(1) # Let the user actually see something!
loginfinal = driver.find_element_by_xpath("//a[@href='AdminLogInFinal.php']") #for login
loginfinal.click()
Login_name= driver.find_element_by_id('user')
driver = webdriver.Edge("MicrosoftWebDriver.exe")
runtest()
错误的
C:\python code>python localwebsitetest.py
Traceback (most recent call last):
File "localwebsitetest.py", line 29, in <module>
runtest()
File "localwebsitetest.py", line 23, in runtest
Login_name= driver.find_element_by_id('user')
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 269, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 752, in find_element
'value': value})['value']
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: No such element