我用虚拟用户填充我的网站,除了出生月份和国家/城市之外,我已将所有内容随机化.
你能帮我找到一个简单的方法吗?这是我现在使用的代码,但它将德国硬编码到它:(
Select user_country = new Select (driver.findElement(By.id("user_country_id")));
user_country.selectByVisibleText("Germany");
Run Code Online (Sandbox Code Playgroud)
这是国家/地区下拉列表的html:
<div class="custom-select">
<select id="user_country_id" class="validate" name="user[country_id]" data-cities-path="/country/id-replace/cities">
<option value="51baca9bf325db50be000012">Japan</option>
<option value="51baca9bf325db50be000015">China</option>
<option value="51baca9bf325db50be00001c">Australia</option>
<option value="51baca9bf325db50be000023">Thailand</option>
</select>
</div>
Run Code Online (Sandbox Code Playgroud) 如何对任何Google地图进行自动化测试.我的项目/应用程序中有一张地图,现在我想点击每个标记.
出于某种原因,当我调用方法Spage.editExButton(int ID)时,我收到一条错误,指出WebElement首先为null.为什么它为空?我使用@FindBy注释定义了它.我必须使用findElement(By.id("xxx"))显式定义元素,以便能够单击它.但为什么我无法使用@FindBy表示法来调用它?
public class SPage extends GPage<SPage> {
public SPage() {
super();
}
public SPage(String pageType) {
super(pageType);
}
@FindBy(id = "xxx")
WebElement first;
public WebElement eButton(int ID) {
first.click();
String tmp = ID + "-Edit";
WebElement edit = getDriver().findElement(By.id(tmp));
return edit;
}
public EPage cEdit(int ID) {
eButton(ID).click();
return new EPage(getBasePageType()).openPage(EPage.class);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在调用这样的方法:
static EPage epage;
static SPage spage;
@Test
public void edit_exception() {
epage = spage.cEdit(IDbefore);
}
Run Code Online (Sandbox Code Playgroud) java selenium webdriver nullpointerexception selenium-webdriver
我有一个自动化聊天应用程序的任务.我正在使用Webdriver和Java.两个不同的用户将同时在两个不同的浏览器上登录并启动聊天.如果有人能给我一些建议,我将不胜感激.
我用chromedriver使用watir webdriver gem.我知道(https://code.google.com/p/chromedriver/issues/detail?id=9#c25)在chromedriver的新版本2.1中有一个特殊的页面加载超时.如何从ruby代码中设置它?
例如:
Scenario:
Given the pageOne page
When I get pageOneTitle
And click the first menu item
And I get the pageTwoTitle
Then pageOneTitle is not equals pageTwoTitle
Run Code Online (Sandbox Code Playgroud)
我有两个课程.每页一个.
该场景的前三个步骤在PageOneSteps中,另一个在PageTwoSteps中.这意味着,pageTitleOne保存在PageOneSteps中.验证步骤然后pageOneTitle不等于PageTwoStele中的pageTwoTitle.
如果PageOneSteps中的pageOneTitle,我如何在PageTwoSteps中等于pageOneTitle和pageTwoTitle?
这是一个非常简单的例子.但我希望它能说明我的意思.
感谢您的支持!
我想知道是否有办法使用By.partialLinkText或By.LinkText在页面上找到第二个(或第三个,第四个等)链接.
我需要能够找到包含相同"部分文本"的多个链接.我想有一个while循环,它将找到第一个,然后是第二个,依此类推.这可能吗?
谢谢,
史蒂夫阿奇博尔德
我更喜欢visibilitOfElementLocated
用来定位元素presenceOfElementLocated
.这样做的原因是它也做了工作presenceOfElementLocated
(如果我错了,请纠正我).
但是很少有情况我可以通过使用presenceOfElementLocated
来实现我的目标,而不是我使用过visibilityOfElementLocated
.
题 :
(或者让我改一下)
presenceOfElementLocated
吗?我最近一直在切换到在Xpath上使用CSS选择器.我遇到了一些我无法解释的事情,我希望有更多知识渊博的人可以提供帮助.
<form id="configure_server">
<div class="form_row">
<div class="form_label">...</div>
<div class="form_input_elements">...</div>
</div>
<input name="serverID" id="serverID" value="2" type="hidden">
<div class="form_row">
<div class="form_label">...</div>
<div class="form_input_elements">...</div>
</div>
<div class="form_row">
<div class="form_label">...</div>
<div class="form_input_elements">...</div>
</div>
<div class="form_row">
<div class="form_label">...</div>
<div class="form_input_elements">...</div>
</div>
<div class="form_row">
<div class="form_label">Name</div>
<div class="form_input_elements">Thor</div>
</div>
<input name="name" id="name" value="Thor" type="hidden">
<div class="form_row">
<div class="form_label">...</div>
<div class="form_input_elements">...</div>
</div>
<div class="form_row">
<div class="form_label">...</div>
<div class="form_input_elements">...</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
我试图获得等于的元素的文本Thor
.
要查找该元素并检索我正在使用的文本:
self.driver.find_element_by_css_selector("#configure_server>div.form_row:nth-child(6)>div.form_input_elements")
Run Code Online (Sandbox Code Playgroud)
我很困惑,我必须使用:nth-child(6)
,我希望使用:nth-child(5)
.任何人都可以解释为什么我必须引用一个指数较高的孩子吗?
我正在尝试编写一个自动测试脚本,它将为多个URL执行一组操作.我试图这样做的原因是因为我正在测试一个具有多个功能完全相同的前端接口的Web应用程序,所以如果我可以使用单个测试脚本来运行所有这些,并确保基础知识是按顺序,这可以节省我在代码库更改时的回归测试中的大量时间.
我目前的代码如下:
# initialize the unittest framework
import unittest
# initialize the selenium framework and grab the toolbox for keyboard output
from selenium import selenium, webdriver
# prepare for the usage of remote browsers
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class Clubmodule(unittest.TestCase):
def setUp(self):
# load up the remote driver and tell it to use Firefox
self.driver = webdriver.Remote(
command_executor="http://127.0.0.1:4444/wd/hub",
desired_capabilities=DesiredCapabilities.FIREFOX)
self.driver.implicitly_wait(3)
def test_010_LoginAdmin(self):
driver = self.driver
# prepare the URL by loading the list from a textfile
with open('urllist.txt', 'r') as …
Run Code Online (Sandbox Code Playgroud)