Selenium2.0 Webdriver Essays

Source: Internet
Author: User

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
    1. ((Ijavascriptexecutor) driver).  Executescript ("Arguments[0].scrollintoview (true);", Element);
[CSharp]View PlainCopy
    1. ((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
    1. Remotewebdriver RW = new Remotewebdriver ();
    2. Remotewebelement re = rw.  Findelementonpage (By.id ("Id"));
    3. Re. Locationinview;
[CSharp]View PlainCopy
      1. Remotewebdriver RW = new Remotewebdriver ();
      2. Remotewebelement re = rw.  Findelementonpage (By.id ("Id"));
      3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.