Java + Selenium element positioning (3) by TagName

Source: Internet
Author: User

This article describes the by tagname method in the Findelement interface. First, you need to know what tagname is. Before we used the F12 developer tool to view the page elements, we found that each line of code had <input>, <body>, <div>, <button>, and so on, and these tags were tagname. But we can all see, like <div>, <button>, <input> these commonly used tags, the frequency is very high in the Web page, if we use tagname to locate elements, we may not be able to locate the element we expected. So it is common to use the Findelements interface to find a set of elements.

For example, I want to make Firefox full-screen, so the first thing I want to do is focus the cursor inside the browser. Focusing on this action can be achieved through tagname. By looking at the page code, we know that a Web page <body> this tag is unique. Then we need to use <body> this tag to complete the focus action. The code shows the following

import java.util.concurrent.TimeUnit; import Org.openqa.selenium.by;import Org.openqa.selenium.keys;import   Org.openqa.selenium.webdriver;import Org.openqa.selenium.firefox.FirefoxDriver;  Public classByclassname { Public Static voidMain (string[] args) throws Exception {System.setproperty ("Webdriver.gecko.driver",". \\Tools\\geckodriver.exe"); Webdriver Driver=NewFirefoxdriver ();                 Driver.manage (). window (). Maximize (); Driver.manage (). Timeouts (). Implicitlywait (5, Timeunit.seconds); Driver.Get("http://news.baidu.com"); Driver.findelement (By.tagname ("Body") . SendKeys (KEYS.F11); }}

For example, I used Firefox instead of the previous Google browser. Because I found that press F11, full screen This operation, in Google Chrome is not successful, no error message. So maybe it's Chromedriver.exe's little bug. The solution to this problem, the follow-up if found, will be updated.

Java + Selenium element positioning (3) by TagName

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.