Created
July 3, 2015 01:40
-
-
Save sophie2805/53d8f3cbc4c9e969052f to your computer and use it in GitHub Desktop.
get the web page, regrex find the specific Chinese content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
import java.util.Calendar; | |
import java.util.concurrent.TimeUnit; | |
import org.junit.*; | |
import static org.junit.Assert.*; | |
import static org.hamcrest.CoreMatchers.*; | |
import org.openqa.selenium.*; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import org.openqa.selenium.support.ui.Select; | |
public class test { | |
private WebDriver driver; | |
private String baseUrl; | |
private boolean acceptNextAlert = true; | |
private StringBuffer verificationErrors = new StringBuffer(); | |
@Before | |
public void setUp() throws Exception { | |
driver = new FirefoxDriver(); | |
baseUrl = "https://www.wacai.com/user/user.action?url=http%3A%2F%2Fbbs.wacai.com%2Fportal.php";//"http://bbs.wacai.com/thread-651750-1-1.html" | |
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); | |
} | |
@Test | |
public void testLogin() throws Exception { | |
driver.get("http://bbs.wacai.com/thread-648905-1-1.html");// + "/user/user.action?url=http%3A%2F%2Fbbs.wacai.com%2Fportal.php"); | |
//System.out.println(driver.getPageSource()); | |
Pattern p = Pattern.compile("回帖内容必须为.+</font>非此内容将收回铜钱奖励");//.+</font>非此内容将收回铜钱奖励 | |
Matcher r = p.matcher("driver.getPageSource().toString()");//(driver.getPageSource().toString()); | |
StringBuffer key = new StringBuffer(); | |
int i = 0; | |
while(r.find()){ | |
key.append(r.group()); | |
} | |
System.out.println(key); | |
} | |
@After | |
public void tearDown() throws Exception { | |
driver.quit(); | |
String verificationErrorString = verificationErrors.toString(); | |
if (!"".equals(verificationErrorString)) { | |
fail(verificationErrorString); | |
} | |
} | |
private boolean isElementPresent(By by) { | |
try { | |
driver.findElement(by); | |
return true; | |
} catch (NoSuchElementException e) { | |
return false; | |
} | |
} | |
private boolean isAlertPresent() { | |
try { | |
driver.switchTo().alert(); | |
return true; | |
} catch (NoAlertPresentException e) { | |
return false; | |
} | |
} | |
private String closeAlertAndGetItsText() { | |
try { | |
Alert alert = driver.switchTo().alert(); | |
String alertText = alert.getText(); | |
if (acceptNextAlert) { | |
alert.accept(); | |
} else { | |
alert.dismiss(); | |
} | |
return alertText; | |
} finally { | |
acceptNextAlert = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment