in selenium, encapsulating it as a way to execute the exe file: /*** Upload files, need to click the popup upload window * *@paramBrowser * Name of the browser used *@paramfile * files and filenames that need to be uploaded*/ Public voidhandleupload (String browser, file file) {string filepath=File.getabsolutepath (); String Executefile= "C:\Users\Administrator\Desktop\upload.exe";//defines the path to the Upload.exe fileString cmd = "\" "+ Executefi
(). Refresh ();Back to Baidu HomeDriver.navigate (). back ();Method 2, an explicit wait, waits within a specified time to occur within a range of 10 seconds. The Red_box element is executed down, and if it doesn't appear after 10 seconds, jump out.webelement element = (new webdriverwait (Driver, ten)). Until (expectedconditions.presenceofelementlocated ("su")) );Advance to search Navigate windowDriver.navigate (). Forward ();Driver.close ();}}Note that if the content that is explicitly waiting
= driver.findelement (By.id ("Father")). Findelement (Bylinktext ("xxx"));4. NosuchelementfoundexceptionThe Findelement () and findelements () methods throw the exception when the corresponding element is not found.Findelements:Selenium Webdriver's Findelements () method allows you to get a collection of specified rules for situations where you need to operate on a similar set of elements.Example: Verify the number of Baidu home navigation links and print out their hyperlink addressImplementati
The simplest way to start a use case1 Building XML firstThe XML code is as follows1 2 3 4 5 class name= "Com.net.www.day_jingdong"/> //The class name that needs to be started is modified to its own. registration. Class name 6 7 8 Right-click Run as in XML to start it.2 testng Boot Sequence control12345className= "Com.net.www.day_jingdong" >6789Tenclass> One A -Selenium-java
1.The element is not a visible to click.Use the 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.OrThen click on the element.2.The
Just contact Selenium, take WordPress publish the article function exercises, enter the article title, Content Post button, Element.click () invalid, can be found elements, from the phenomenon of script run, feel just the mouse pointer moved to the element, The click operation is not performed and the relevant code is as follows:The methods you have tried are:
A post about the click () and the Submit () difference is found, saying that Click
1. Alert, first use the normal method to locate the button that triggers the Alert, and thenAlert alert = Driver.switchto (). alert (); Alert.accept ();If the alert box is confirmed, it is OK to pop the alert box continuously, continue the same operation, pay attention to the delay ... Otherwise it could be too fast, wrong, pit.Alert alert = Driver.switchto (). alert (); Alert.accept (); Thread.Sleep (+); alert = Driver.switchto (). alert (); Alert.accept ();2. ConfirmAlert confirm = Driver.swit
Package Seleniumlearn1;import Java.io.file;import Java.io.fileoutputstream;import java.io.ioexception;import Java.util.list;import Org.openqa.selenium.by;import Org.openqa.selenium.webdriver;import Org.openqa.selenium.webelement;import Org.openqa.selenium.chrome.chromedriver;import com.gargoylesoftware.htmlunit.javascript.host.element;/** * Get http://www.qyer.com page, all selenium+java-find URLs that co
parameter format requirement) -String size =string.valueof (Links.size ()); + //String size = integer.tostring (Links.size ()); A //String size = links.size () + ""; at //Verify the number of links -Selenesetestnghelper.assertequals ("8", size); - - //Print href attribute - //get all the elements in the list through a for loop, and then call the GetAttribute () method to get the attributes of the element - for(inti=0; I){ inSystem.out.pr
First, the scene: in the non-logoff system switch different account login system, login will have browser cache, resulting in unusually slow logon time. is related to developing the browser cache processing mechanism.Second, the solution:Gets the browser cookie, adding code to clear the cache before the login method. Import Org.openqa.selenium.Cookie; // Get Cookies Set// print Cookie logger.info (COO); // clears all cache driver.manage (). Deleteallcookies ();
Today, when you run an Automation use case, you find that an element always hints at not clickable. The reason for the analysis is probably the big top icon in the bottom right corner of the page, just blocking the element I want to click. To solve it, you have to pull the page, you need to manipulate the scroll bar on the page.A relatively simple method is used, which is documented here: Javascriptexecutor js= (javascriptexecutor) driver;String high= "Scroll (0,10000);"; /scroll to the Y val
(); Select a single optionRadio.clear (); Clear a single optionRadio.isselected (); Determine if a single option has been selected6. Multi-check boxwebelement checkbox = Driver.findelement (By.id ("MyCheckBox."));Checkbox.click ();Checkbox.clear ();Checkbox.isselected ();Checkbox.isenabled ();6. Popup dialog boxAlert alert = Driver.switchto (). alert ();Alert.accept (); Are you sureAlert.dismiss (); CancelAlert.gettext (); Get text7. Formswebelement approve = driver.findelement (By.id ("approve
index number to locate
In the tested Web page, look for the query button in the second div tag
INPUT[2]
webelement button = driver.findelement (By.xpath ("//input[2]"));
Use Page properties to locate
Locate the first picture element in the page being tested
img[@alt = ' div1-img1 ']
webelement button = driver.findelement (By.xpath ("//img[@alt = ' div1-img1 ')");
Fuzzy positioning Starts-with Keywords
Find pictures alt attribute start position contains elements
the previous steps, we click on the line of code that knows the element we want to get. At this point, we move the mouse over the line code, right-click and select Copy---copy Xpath. This allows us to get an XPath expression for that element. We can see the XPath expression only by selecting paste in any of the input boxes. For example, our Baidu homepage example. Or the input box of the home page, after this wave operation, we can get the XPath expression to the input box://*[@id = "kw"]. So w
Most of the Java projects are now based on Maven, using SELENIUM2 in the MAVEN project. Very simple.
First, you need to configure the MAVEN environment.
You can refer to the MAVEN installation and the Eclipse configuration Maven
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.