Skip to content

Instantly share code, notes, and snippets.

// Define Package Name
package wpAdmin;
// Import Selenium Libraries
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
// Define Class Name
// Navigate to the title box and enter the title
driver.findElement(By.id("title-prompt-text")).sendKeys("<Post Title>");
// Change the editor to the basic HTML editor
driver.findElement(By.id("content-html")).click();
// Navigate to the content area and enter the post content
driver.findElement(By.className("wp-editor-area")).sendKeys("<Post Content>");
// Navigate to the tags area and input the tags seperated by ,
// Click on the post link from the left navigation bar and navigate to All Post page
driver.findElement(By.xpath("//*[@id='menu-posts']/a/div[2]")).click();
// Open the New Post page by clicking on the Add Post button
driver.findElement(By.xpath("//*[@id='wpbody-content']/div[3]/h1/a")).click();
// Registration URL
String regurl = "http://<YourWebsiteURL>/wp-login.php";
// Opening New Firefox Window
WebDriver driver = new FirefoxDriver();
// Open Registration URL
driver.get(regurl);
// Maximize the browser window
// Finding Username element and entering values
driver.findElement(By.id("user_login")).sendKeys("<username>");
// Finding Email element and entering values
driver.findElement(By.id("user_pass")).sendKeys("<password>");
// Finding Submit button and Clicking it
driver.findElement(By.id("wp-submit")).click();
@shahaakash
shahaakash / BasicSelenium.java
Last active January 28, 2016 09:34
Basic Selenium WebDriver Automation Script Structure
// Define Package Name
package wpAdmin;
// Import Selenium Libraries
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
// Define Class Name