问题描述:

I am doing automated tests on MS Edge, I am unable to do send keys to the text field of my local website.

I am using Python 2.7 and a proper version of 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()

Errors: Edge does not perform send keys

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

I have tried only find element by id but it does not work.

Here is my code

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()

Error

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

相关阅读:
Top