- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我缺少一些非常基本的东西。我想,无论我能收集到什么,我都需要在我键入时下拉列表的 id
。获得 id
后,我想我可以获取列表并遍历它。
自动完成的 Web 代码是:
<div class="col-md-12">
<label>Google Map Location*</label>
<input id="searchTextField" type="text" class="form-control" placeholder="Enter a location" autocomplete="on" required="required">
<input id="latitude" type="text" style="display: none;" class="form-control" value="">
<input id="longitude" type="text" style="display: none;"class="form-control" value="">
<p class="help-block" style="color: #737373;">Instruction: Please drag the marker to get exact location of the IT park.</p>
</div>
初始化js代码的javascript是
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.bindTo('bounds', map);
Selenium 代码是:
autocompleteElement = God.getWebElementById("searchTextField");
autocompleteElement.sendKeys("Airport");
List<WebElement> autoCompleteList = Initialize.getInstance().getDriver().findElements(
By.className("form-control");
for (WebElement autocompleteItem : autoCompleteList) {
if (autocompleteItem.getText().contains("Pune Airport")) {
autocompleteItem.click();
}
break;
}
我收到 autocompleteItem
is null or empty。
编辑 1
我是 javascript
的新手,我继承了这个代码库。我不明白的是如何将 locator
或 id
分配给容器,以便我可以遍历 WebElement
并执行点击
我想要的结果。
编辑2
我添加了自动完成检查元素的快照。下面的答案指的是 xpath(“对我来说非常复杂的东西”)。在我的特定情况下,我应该用什么替换 xpath?
或
您需要什么帮助我获取下拉列表列表?
编辑3
我像这样使用类名 form-control
List<WebElement> autoCompleteList = waitForElementByClass(
"form-control");
System.out.println("autocomplete list size " + autoCompleteList.size());
for (WebElement autocompleteItem : autoCompleteList) {
if (autocompleteItem.getText().contains("Wadgaon Sheri")) {
System.out.println("auto complete selected " + autocompleteItem.getText());
autocompleteItem.click();
break;
} else
System.out.println("no match, tagname:" + autocompleteItem.getTagName() + "point:"
+ autocompleteItem.getLocation());
}
并得到以下输出。请注意 autocompleteItem.getText
返回了一个空字符串。
autocomplete list size 16
no match, tagname:inputpoint:(255, 200)
no match, tagname:selectpoint:(255, 274)
no match, tagname:inputpoint:(255, 433)
no match, tagname:selectpoint:(255, 509)
no match, tagname:inputpoint:(255, 553)
no match, tagname:inputpoint:(330, 553)
no match, tagname:inputpoint:(255, 627)
no match, tagname:textareapoint:(525, 200)
no match, tagname:textareapoint:(525, 324)
no match, tagname:inputpoint:(525, 450)
no match, tagname:inputpoint:(525, 526)
no match, tagname:inputpoint:(525, 602)
no match, tagname:inputpoint:(525, 678)
no match, tagname:inputpoint:(796, 200)
no match, tagname:inputpoint:(0, 0)
no match, tagname:inputpoint:(0, 0)
我现在正在尝试使用类名 pac-container pac.logo
然后我也会尝试使用 div.pac-container.pac-logo
:)。请记住,我的 javascript 技能不是太好。
编辑 4现在,我尝试将类名设为 pac-container pac.logo
、pac-container.pac-logo
、div.pac-container.pac.logo
和 pac-container
,
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className(byclass)));
是代码卡在这里吗
如果我将行替换为
wait.until(ExpectedConditions.elementToBeSelected(God.getWebElementByClassNae(byclass)));
我得到一个 NoElementFoundException
。
所以我最接近解决这个问题的方法是找到该死的下拉列表的类名。
public List<WebElement> waitForElementByClass(String byclass) {
WebDriverWait wait = new WebDriverWait(God.getCurrentBrowser(), 2000);
List<WebElement> elements = null;
boolean waitForElement = true;
System.out.print("Waiting for " + byclass);
do {
System.out.print(".");
try {
//wait.until(ExpectedConditions.visibilityOfElementLocated(By.className(byclass))); wait.until(ExpectedConditions.elementToBeSelected(God.getWebElementByClassNae(byclass)));
waitForElement = false;
System.out.println("found");
elements = God.getWebElementsByClassName(byclass);
} catch (NoSuchElementException e) {
waitForElement = true;
} catch (TimeoutException e) {
waitForElement = false;
return null;
}
} while (waitForElement);
return elements;
}
最佳答案
使用 WebDriverWait 插入代码以等待元素可见。下面的示例,
WebDriverWait wait = new WebDriverWait(driver,10000);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("form-control")));
关于java - Selenium 测试在谷歌反向查找时自动完成失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40805021/
我能否获得一个具有两个参数的递归Prolog谓词,称为反向,它返回列表的反向: 示例查询和预期结果: α-反向([a,b,c],L)。 L = [c,b,a]。 由两个称为palindrome的参数组
在使用 get_dummies() 将分类数据转换为数字数据后,我的数据框看起来像这样 score1 score2 country_CN country _AU category_leader ca
我有一张 table ,上面有一个国家/地区列表。说这些国家之一是“马其顿” 如果搜索“马其顿共和国”,什么 SQL 查询会返回“马其顿”记录? 我相信在 linq 中它会是这样的 var count
我们有一个角色继承结构,它假设每个人都默认获得最低级别的角色,而不是最高级别的过滤,如下图所示: role.Everyone //lowest level; everyone gets this ro
我正在使用 $.each() 解析数组,但在其中,我使用 .splice() 方法,因此我需要向后迭代。这可能吗? var store = [...]; //... var rules = [...]
我有一个 SPLObjectStorage 对象,其中 Player 对象作为键,分数作为与之关联的信息。玩家对象按照从最高分到最低分的顺序添加到存储中,但我现在需要以相反的顺序遍历它们。 我还需要能
我无法理解这一点:如果我给 Prolog reverse([], A). 它工作得很好,如果我给它 reverse(A, [] ). 并根据第一个建议回答 ; 它挂起!为什么? (GNU Prolog
我有一个 SPLObjectStorage 对象,其中 Player 对象作为键,分数作为与之关联的信息。玩家对象按照从最高分到最低分的顺序添加到存储中,但我现在需要以相反的顺序遍历它们。 我还需要能
我有一个HashMap看起来像: HashMap playerHashMap = new HashMap<>(); 玩家是包含姓名、号码、年龄等的对象。 现在我已经对它进行了排序,它看起来像这样: k
我有这个: file://localhost/Volumes/Untitled%20RAID%20Set%201/Callum/iTunes/Music/Steppenwolf/Steppenwolf
我正在使用 std::regex 并希望找到与某个用户定义的正则表达式字符串匹配的字符串中的最后一个位置。 例如,给定正则表达式 :.* 和字符串“test:55:last”,我想找到“:last”,
有一个表 ServErog(服务),它被重新引导到 4 个表 ServA、ServB、ServC、ServD(它们是不同的非统一服务),其中包含 servtype(服务类型)和 type_id(来自其
这个问题在这里已经有了答案: What is the best way to convert date from JavaScript string in format YYYYMMDD to Ja
我知道如何获得包含几个词的所有结果: SELECT * FROM `table` WHERE MATCH (`row`) AGAINST ('+word1 +word2' IN BOOLEAN MOD
你好,我有这个 html 代码: .container{ width: 450; height: 400; border:1px solid
我想知道是否有任何方法可以使用相同的 CSS 过渡实例来将其向前移动然后向后/向后移动。例如,假设我有这种转变: @-webkit-keyframes fade-transition { fr
假设我有这些字符串: char ref[30] = "1234567891234567891"; char oth[30] = "1234567891234567891"; 我想在 C++ 中使用 S
所以我有这段代码,它使 xcode 崩溃 void strrev(const std::string& str) { for(size_t i=str.length();i>=0;i--)
我正在使用下面的代码使每张图片 1 对 1 淡入淡出。我怎样才能反向执行此操作以使图片以相反的顺序加载? img {display:none;} $('img').each(function(
我正在尝试弄清楚如何改变 FrameLayout 堆叠其子项的方式。 目前它是最新的(先进先出)。我想更改它,使最新的 child 位于底部(FILO)。我试着查看 FrameLayout 的源代码,
我是一名优秀的程序员,十分优秀!