【发布时间】:2018-04-29 01:39:00
【问题描述】:
我正在尝试在 Selenium 中编写一个测试,以确保输入到一个输入中的文本镜像到另一个输入中。我在下面不断收到此错误。
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div/div[2]/div/div/div/div[2]/div[1]/input[1]"}
这是我目前正在使用的代码:
class inputMirror(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.get("https://foo.bar")
def test_mirror_input(self):
#Ensures text from the first input is mirrored into the second input box
driver = self.driver
userInput = "Howdy"
inputBoxOneXpath = driver.find_element_by_xpath('/html/body/div/div[2]/div/div/div/div[2]/div[1]/input[1]')
inputBoxTwoXpath = driver.find_element_by_xpath('/html/body/div/div[2]/div/div/div/div[2]/div[1]/input[2]')
inputBoxOneXpath.clear()
inputBoxOneXpath.send_keys(userInput)
driver.implicitly_wait(10)
assert inputBoxTwoXpath.text == userInput
driver.close()
HTML 代码:
<input type="text" placeholder="Enter text here..." value="">
<input class="textbox" placeholder="Enter text here..." value="" maxlength="80" required="true">
【问题讨论】:
-
能否提供正确的 HTML 代码?
-
将 html 添加到问题中,如果不清楚,请告诉我。
-
在您的代码中,您使用的是绝对 xpath。使用提供的 html 没有人可以帮助您解决您的错误。
标签: python selenium automation automated-tests