这根本不是技术问题.但是,我无法找到应该使用以下内容生成的.HTML报告:
py.test --cov-report html pytest/01_smoke.py
我确信它会将它放在父位置或测试脚本位置.我和我都找不到.所以我认为它根本没有生成?
问题:
无法从css选择器中选择特定元素.需要验证注册用户是否可以成功更改密码.我已经尝试了类的不同属性来调用它.尝试使用前两个示例时,结果是方法中出现异常错误.最后一次尝试调用第一个类实例并重置密码字段(失败).
尝试:
driver.find_element_by_css_selector("value.Update").click()
driver.find_element_by_css_selector("type.submit").click()
driver.find_element_by_css_selector("input.test_button4").click()
Run Code Online (Sandbox Code Playgroud)
目的:
我需要选择共享同一个类的项目.如下所示,该课程是共享的.
form id="changepw_form" name="changepw" action="#" method="post">
<div class="field3">
<div class="field3">
<div class="field3">
<input class="test_button4" type="reset" value="Reset" style"font-size:21px"="">
<input class="test_button4" type="submit" value="Update" style"font-size:21px"="">
Run Code Online (Sandbox Code Playgroud) 在网站上运行 Selenium 测试时,我有一些 Flash 元素无法使用 Selenium/Python 进行测试。我想调用一个单独的终端窗口,运行 Sikuli OCR 测试,然后回到 Selenium/Python 测试。我一直无法弄清楚这一点。我把 XXX 放在我不知道新终端打开和运行 Sikuli 脚本的参数的地方。
def test_05(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_link_text("Home").click()
driver.find_element_by_id("open_popup").click()
driver.find_element_by_id("screen_name").send_keys("user")
driver.find_element_by_id("password").send_keys("pwd")
driver.find_element_by_id("login_submit").click()
driver.find_element_by_id("button").click()
time.sleep(120)
os.system('XXX')
os.system('./Sikuli/sikuli-script -r test.sikuli')
Run Code Online (Sandbox Code Playgroud)
我确定这里有几个项目是错误的。任何帮助将不胜感激。我已经搜索并阅读了我可以找到的内容,但无法全部协同工作。
我试图验证页面上是否存在该文本.通过ID验证元素很简单,尝试使用文本进行操作是不正常的.并且,我找不到By的正确属性来验证网页上的文本.
使用By属性为ID工作的示例
self.assertTrue(self.is_element_present(By.ID, "FOO"))
Run Code Online (Sandbox Code Playgroud)
示例我尝试使用By属性使用(不起作用)文本
self.assertTrue(self.is_element_present(By.TEXT, "BAR"))
Run Code Online (Sandbox Code Playgroud)
我也试过这些,有*错误(下面)
self.assertTrue(self.is_text_present("FOO"))
Run Code Online (Sandbox Code Playgroud)
和
self.assertTrue(self.driver.is_text_present("FOO"))
Run Code Online (Sandbox Code Playgroud)
*error:AttributeError:'WebDriver'对象没有属性'is_element_present'
在尝试验证时我也有同样的问题By.Image.
我的问题:能够检测到警报框已打开,请验证警报中的文本,确认文本,然后关闭警报。然后,返回并更正无效的电子邮件。
我的测试是用于注册用户的测试。我需要验证何时有人可能输入了错误的数据或不匹配的数据。在这种情况下,我要输入电子邮件并验证首次输入的电子邮件。如果它们不匹配,则会出现一个弹出窗口,警告用户检查他们输入的和匹配的电子邮件地址。到目前为止,我只能得到一个错误。
错误:
E UnexpectedAlertPresentException:消息:存在“模态对话框”;Stacktrace:方法nsCommandProcessor.prototype.execute在file:///var/folders/1j/x3cxkrqn3sscdyq0t36169hr0000gn/T/tmpTCqMgm/extensions/fxdriver@googlecode.com/components/command_processor.js中抛出错误
我以为我的代码可以解决这个问题,但是不行。如果有人指出我对您来说很明显,那么我将不胜感激。
我的整个测试代码:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
class ChallengeTests(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(5)
self.base_url = "https://www.testpage.com"
self.verificationErrors = []
self.accept_next_alert = True
# SIGN UP NEW USER
def test_00_sign_up(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_id("remail").send_keys("foobar@me.com")
driver.find_element_by_id("remail_confirm").send_keys("bar@me.com")
driver.find_element_by_id("next").click()
alert = self.driver.switch_to_alert()
alert = self.assertTrue(self.is_text_present("The email addresses you entered"))
driver.find_element_by_id("remail_confirm").send_keys("foobar@me.com")
driver.find_element_by_id("registration_button").click()
# NON TESTS
def is_element_present(self, how, what):
try: …Run Code Online (Sandbox Code Playgroud) 问题:如何读取嵌套中的值<div>?
情况:我正在我们的网站上测试注册.为了完成该过程,用户将需要输入验证码.使用帮助程序类(在我们的开发服务器上),我们可以显示(隐藏)当前的验证码.我需要抓住它并保存它以供.send_keys函数使用(该部分是简单的部分).我没有代码与我正在使用的东西分享,因为我甚至不确定在哪里跳.
好吧,我有这个,但这显然不是答案:
driver.find_element_by_id("capchta").send_keys("foobar")
Run Code Online (Sandbox Code Playgroud)
在上面,我可以发送一个键值(看作"foobar").我只需要用我在中读到的字符串替换"foobar"value=XXX
这是带有验证码的HTML代码,用value=XXXX.表示.
<div id="code_area">
<p id="captcha_blurb">Please enter the security code below</p>
<div id="capchta_area">
<img id="secuity_icon" src="/img3/Secuity-Icon.png">
<img id="security-image" src="data:image/png;==">
<input id="current_captcha" type="hidden" value="XXXX">
<input id="capchta" class="reg_form_input" value="" name="code" placeholder="Enter Security Code" title=" Please Enter These Characters." onblur="removeInputInfoBox('reg_box');" onfocus="addInputInfoBox('#capchta','#capchta_area', 'reg_box');">
</div>
Run Code Online (Sandbox Code Playgroud) 我正在使用Sikuli OCR测试库.在我的Python脚本中,我正在寻找两个可能出现的图像之一.当其中一个出现时,如果选择该对象.
但是,我想让脚本结束.它没有.我试过了quit(),exit()但那不是这样做的.除了while循环和完成脚本之外,它工作正常.
while True:
if exists ("lose.png"):
click ("lose.png")
print ("***** YOU LOSE! *****")
if exists ("win.png"):
click ("win.png")
print ("***** YOU WIN! *****")
StopIteration
quit()
Run Code Online (Sandbox Code Playgroud)