selenium中如何定位提现按钮
package test1;import org.openqa.selenium.By;
import org.openqa.selenium.chrome.*;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.support.ui.Select;
public class Bdudengl {
public static void main(String[] agrs){
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://10.1.50.26/");
driver.findElement(By.name("user")).clear();
driver.findElement(By.name("user")).sendKeys("510722198908154337");
driver.findElement(By.name("pass")).clear();
driver.findElement(By.name("pass")).sendKeys("121212");
driver.findElement(By.name("rand")).clear();
driver.findElement(By.name("rand")).sendKeys("1111");
driver.findElement(By.id("my_login_login")).click();
driver.findElement(By.id("my_homepage_cashbox_buy")).click();
driver.findElement(By.name("applicationAmount")).clear();
driver.findElement(By.name("applicationAmount")).sendKeys("1000");
driver.findElement(By.name("transPwd")).clear();
driver.findElement(By.name("transPwd")).sendKeys("121212");
driver.findElement(By.name("rand")).clear();
driver.findElement(By.name("rand")).sendKeys("1111");
driver.findElement(By.name("forceDeal")).click();
driver.findElement(By.cssSelector("button.btn_red")).click();
System.out.print("test");
//driver.quit();
}
}
driver.findElement(By.cssSelector("button.btn_red")).click();——————这一步点击后没有反应?
不要用这种元素定位方法,换一个定位方法试试呗,xpath方法肯定可以定位到 踏雪飞狐 发表于 2015-8-6 17:49
不要用这种元素定位方法,换一个定位方法试试呗,xpath方法肯定可以定位到
driver.findElement(By.xpath("html/body/div/div/div/div/div/form/div/dl/dd/button")).click();
用XPATH也不行,这条代码已经执行了,好像也点到了按钮,但是界面没有反应,后面的代码已经执行了 没遇到过这种情况 哪位大神能帮忙解决下; lpwsxz 发表于 2015-8-7 09:43
driver.findElement(By.xpath("html/body/div/div/div/div/div/form/div/dl/dd/button")). ...
试试下面的方法:
1、sleep一定的时间,Thread.sleep(5000);
或者2、等待某个元素出现后再进行操作
public WebElement getElement(final By by) {
boolean flag = new WebDriverWait(driver, 5)
.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.findElement(by).isDisplayed();
}
});
WebElement element = null;
if (flag) {
element = driver.findElement(by);
}
return element;
} lpwsxz 发表于 2015-8-7 09:43
driver.findElement(By.xpath("html/body/div/div/div/div/div/form/div/dl/dd/button")). ...
试试下面的方法:
1、sleep一定的时间,Thread.sleep(5000);
或者2、等待某个元素出现后再进行操作
public WebElement getElement(final By by) {
boolean flag = new WebDriverWait(driver, 5)
.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.findElement(by).isDisplayed();
}
});
WebElement element = null;
if (flag) {
element = driver.findElement(by);
}
return element;
} 本帖最后由 testingstudying 于 2015-10-13 11:01 编辑
我也遇到了这种情况,后面的代码都执行了,但是点击按钮后没反应,是否需要用submit
页:
[1]