简体   繁体   中英

how to locate the element in <div aria-label>

I am very beginner level in selenium java. I am trying to find the element in amazon.

when I try to run this code, I could not locate the element. please help to fix this.

enter image description here

This is my code

    WebElement a_review= driver.findElement(By.xpath("//div[@aria-label='4 Stars & Up']"));
            ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", a_review);
            a_review.click();

Here you can simply click the element without using javascript. Please try the following code:

driver.get("https://www.amazon.in/s/ref=mega_sv_s23_1_2_1_2?rh=i%3Ashoes%2Cn%3A1983633031&ie=UTF8&lo=shoes");
driver.findElement(By.xpath("//div[@aria-label='4 Stars & Up']")).click();

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