Webdriver can ' t action the element when the element was out of view
1. Scroll to the element
Use JavaScript to scroll the element to view
[CSharp]View Plaincopy
- ((Ijavascriptexecutor) driver). Executescript ("Arguments[0].scrollintoview (true);", Element);
[CSharp]View PlainCopy
- ((Ijavascriptexecutor) driver). Executescript ("Arguments[0].scrollintoview (true);", Element);
2. Use location to view
Use Locationinview property need use Remotewebdriver and remotewebelement
Code like:
[CSharp]View Plaincopy
- Remotewebdriver RW = new Remotewebdriver ();
- Remotewebelement re = rw. Findelementonpage (By.id ("Id"));
- Re. Locationinview;
[CSharp]View PlainCopy
- Remotewebdriver RW = new Remotewebdriver ();
- Remotewebelement re = rw. Findelementonpage (By.id ("Id"));
- Re. Locationinview;
Keypress (String locator, String keysequence)
Selenium. KeyPress ("Id=rd_a", "\\40")
Display has these values, none, Inline,block ..., I changed none to block, can also change the Visiblility:hidden to visible
javascriptexecutorj= (javascriptexecutor) driver;
J.executescript ("Document.findelementbyid (' 123 '). style.display= ' block ';");
And then Webelement.sendkeys ("C:\abc.txt");
XPath can use "//" and "/" to split the path when locating a node closer to the target, "//" to indicate a relative path, and to navigate directly to the element, regardless of its position;
"/" represents the absolute path, which is the immediate child element under the current directory.
For example, you can use this method to enter a character in the input box.
Action.click (Element). SendKeys (Keystosend).
This method can also be combined into:
Action.sendkeys (Element,keystosend);
In the process of writing selenium automation, you often encounter problems such as:
1. In the same page to do the operation, such as clicking on a button, pop up a box, then click another button, and then pop up a box
2. If the second click clicks again after the first click operation, an error occurs because the previous popup box still appears on the front.
3. In the actual manual operation, click on the first box, click on the blank area, click on the second box appears. Therefore, consider a way to click on an empty area
The implementation method is as follows
/** * 点击空白区域:坐标(0,0) */public static void clickBlankArea(WebDriver driver) { Actions actions = new Actions(driver); actions.moveByOffset(0, 0).click().build().perform();}
Let driver first move to a blank position (this is set to (0,0) coordinate point), do a click action
Selenium2.0 Webdriver Essays