ziyao

  博客园 :: :: 博问 :: 闪存 :: 新随笔 :: :: :: 管理 ::

鼠标刚好位于下拉列表上面  tooltip显示   导致当点击tooltip后面的菜单栏失败ElementClickInterceptedException  is not clickable at point

 

 

数据驱动的自动化经常可能会有根据数据是否有值来执行操作

String data = testData.getxxx()
if(data != null) {
    // to do something
}
// instead of it, using JDK8 Optional
Optional.ofNullable(testData.getxxx()).ifPresent( data -> {
    / /to so something
})

Best Way to Store Locators: http://stackoverflow.com/questions/28091455/best-way-to-store-locators

切换不同的topaccount 要确保页面的account tree的drop downlist 也要同时刷新 所以要验证account drop down tree的数据
方式1: 获取drop down 下面的items 循环比较
方式1: 获取dropdown item 父元素 比较父元素的innerText

1. How to Resolve Stale Element Reference Exception?

First of all lets be clear about what a WebElement is: A WebElement is a reference to an element in the DOM.
A StaleElementException is thrown when the element you were interacting is destroyed and then recreated. Most complex web pages these days will move things about on the fly as the user interacts with it and this requires elements in the DOM to be destroyed and recreated.
When this happens the reference to the element in the DOM that you previously had becomes stale and you are no longer able to use this reference to interact with the element in the DOM. When this happens you will need to refresh your reference, or in real world terms find the element again.
Sometimes you see the exception when you build your testing while debug not, that because when you debug, the client is not as fast as if you just run a unit test or a maven build. This means in debug mode the client has more time to prepare the element, but if the build is running the same code he is much faster and the WebElement your looking for is might not visible in the DOM of the Page.

Sleep for some time to wait the element attached to DOM before interact with them 

public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator)

An expectation for checking that an element is present on the DOM of a page. This does not necessarily mean that the element is visible.

public static ExpectedCondition<WebElement> visibilityOfElementLocated(final By locator)

Visibility means that the element is not only displayed but also has a height and width that is greater than 0.

2.输入框输入字后需要点击一下屏幕其他地方触发数据校验 怎么实现?
  比如我在一个输入框书写一个名字后 需要点击屏幕空白地区 来确认我输入的没问题
  需要这样操作的话,可以不一定非得要点击空白区域,因为空白区域对应selenium来说没法操作。可以点击一个没有连接的静态图片或者文字,也是一样的效果

3. driver.manage().deleteAllCookies();
  在webdriver 启动浏览器的时候,它会启动一个干净的,也就是说没有插件,没有cookies, 没有任务的浏览器,所以在刚启动的时候如果不需要测试浏览器,也没有必要调用deleteAllCookies()方法。Tested with IE, Chrome, FF.

4. Input element, readonly and no value attribute

 

5. 在指定的当前节点下搜索满足要求的节点 

在通过selenium使用xpath选择节点的时候,可能会遇到这么一种情况:在指定的当前节点下搜索满足要求的节点

node = driver.find_element_by_xpath("//div[@class='WB_cardwrap S_bg2 clearfix']")
BZNC = node.find_element_by_xpath("//div[@class='feed_content wbcon']/a[@class='W_texta W_fb']").text
BZZY = node.find_element_by_xpath("//div[@class='feed_content wbcon']/a[@class='W_texta W_fb']").get_attribute("href")

以上代码有什么错误吗?貌似没有,一切都很完美。
先拿到node节点,然后在node节点的子节点中搜索满足条件的节点并取出text及属性。
but!运行的结果却是把整个html中所有满足条件的节点都找出来了,而并非是node节点下的!!!仔细想一想,"//div"貌似就是搜索整个html下的div,即使是node下的find_element_by_xpath方法!
所以,只需要在”//”前面加上表示当前路径的"."既可,也就是node.find_element_by_xpath(“.//div”)

/**
* Find the first {@link WebElement} using the given method. See the note in
* {@link #findElements(By)} about finding via XPath.
* This method is affected by the 'implicit wait' times in force at the time of execution.
* The findElement(..) invocation will return a matching row, or try again repeatedly until
* the configured timeout is reached.

* findElement should not be used to look for non-present elements, use {@link #findElements(By)}
* and assert zero length response instead.*

* @param by The locating mechanism
* @return The first matching element on the current context.
* @throws NoSuchElementException If no matching elements are found
* @see org.openqa.selenium.By
* @see org.openqa.selenium.WebDriver.Timeouts
*/

WebElement findElement(By by);

public WebElement getElement(WebElement ancestor, UIElement uiElement){
  WebElement element = null;
  element = ancestor.findElement(uiElement.getBy());
  return element;
}

WebElement deleteWE = viewWE.findElement(By.xpath("./../span[contains(@class, 'glyphicon-minus-sign')]"));  

6. Element is not clickable at point (411, 675). Other element would receive the click: ..." 
This is caused by following 3 types: 
1.The element is not visible to click. 
Use Actions or JavascriptExecutor for making it to click.

By Actions:

WebElement element = driver.findElement(By("element_path"));
Actions actions = new Actions(driver); actions.moveToElement(element).click().perform();
By JavascriptExecutor:
JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("scroll(250, 0)"); // if the element is on top. jse.executeScript("scroll(0, 250)"); // if the element is on bottom.
or
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].scrollIntoView()", Webelement);
Then click on the element.
2.The page is getting refreshed before it is clicking the element. 
For this, make the page to wait for few seconds.
3. The element is clickable but there is a spinner/overlay on top of it
The below code will wait until the overlay disppears
By loadingImage = By.id("loading image ID");
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); wait.until(ExpectedConditions.invisibilityOfElementLocated(loadingImage));
Then click on the element.

Element.scrollIntoViewIfNeeded(boolean opt_center) // recommend false
The Element.scrollIntoViewIfNeeded() method scrolls the current element into the visible area of the browser window if it's not already within the visible area of the browser window. If the element is already within the visible area of the browser window, then no scrolling takes place. This method is a proprietary variation of the standard Element.scrollIntoView() method.
Parameters
opt_center
Is an optional Boolean value with a default value of true:
If true, the element will be aligned so it is centered within the visible area of the scrollable ancestor.
If false, the element will be aligned to the nearest edge of the visible area of the scrollable ancestor. Depending on which edge of the visible area is closest to the element, either the top of the element will be aligned to the top edge of the visible area, or the bottom edge of the element will be aligned to the bottom edge of the visible area.

element.scrollIntoView(); // Equivalent to element.scrollIntoView(true)
element.scrollIntoView(alignToTop); // Boolean arguments
element.scrollIntoView(scrollIntoViewOptions); // Object argument
Is a Boolean value:
If true, the top of the element will be aligned to the top of the visible area of the scrollable ancestor. This is the default value.
If false, the bottom of the element will be aligned to the bottom of the visible area of the scrollable ancestor.

posted on 2016-12-14 11:17  ziyao  阅读(460)  评论(0编辑  收藏  举报