简体   繁体   中英

Selenium Webdriver, click a button with class

在Java中,如何单击带有类的按钮,没有ID,XPath或类名?

You can click by the compose text with xpath

driver.findElement(By.xpath("//div[contains(text(), 'COMPOSE')]")).click();

Or with cssSelector

driver.findElement(By.cssSelector("div:contains('COMPOSE')")).click();

你可以使用这个指令

driver.findElement(By.cssSelector("input[type='button']")).click();

作为XPath:

//div[@class='T-I J-J5-Ji T-I-KE L3']
WebElement composeBtn = driver.findElement(By.xpath("//*[@class='T-I J-J5-Ji T-I-KE L3']"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", composeBtn);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM