????你需要在selenium中通过Mouse actions概念。 ??
????您可以使用以下代码: ??
Actions action=new Actions(driver); // move mouse to Electronics option action.moveToElement(driver.findElement(By.xpath("(//span[@class='_1QZ6fC _3Lgyp8'])[1]"))); action.perform(); // move mouse to MI option action.moveToElement(driver.findElement(By.xpath("//li[@class='Wbt_B2 _3mmoXN']//a[@title='Mi'][contains(text(),'Mi')]"))); action.click(); // click on MI option action.perform(); // perform action
????请使用下面的代码以启动Flipkart并单击Mi. ??
??
import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.Test; public class Testing { public static WebDriver driver; @Test public void test() throws InterruptedException { System.setProperty("webdriver.chrome.driver", "./Driver/chromedriver"); driver = new ChromeDriver(); driver.get("https://www.flipkart.com/"); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS); driver.findElement(By.xpath("//div[@class='mCRfo9']/div/div/button")).click(); Thread.sleep(2000); driver.findElement(By.xpath("//*[text()=\"Electronics\"]")).click(); driver.findElement(By.linkText("Mi")).click(); } }
????如果有帮助,请提出并接受答复。 ??