【发布时间】:2021-05-01 16:59:04
【问题描述】:
我正在学习自动化,这是我的第二个脚本..我想做一些非常简单的事情,转到 https://demoqa.com/ 点击小部件,然后点击滑块,但我尝试了所有元素,但它不起作用......我不能尝试使用 Select 因为我有 ul il 但没有价值。 我也尝试了不可见的页脚元素,但它也不起作用..这是我的代码......(记住我在这方面真的很新......)我以我尝试的所有方式留下了评论
package paginas;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Slider {
//Identify all elements to use
//Poblem: Unable to locate the element
//@FindBy(className="btn btn-light active")
//Problem: element not interactable
//@FindBy(id="item-3")
//Problem (abs xpath):element click intercepted: Element <li class="btn btn-light " id="item-3">...</li>
//is not clickable at point (177, 621). Other element would receive the click: <footer>...</footer>
//@FindBy(xpath="/html[1]/body[1]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[4]/div[1]/ul[1]/li[4]")
//Problem (Rel xpath: element click intercepted: Element <li class="btn btn-light " id="item-3">...</li>
//is not clickable at point (177, 621). Other element would receive the click: <footer>...</footer>)
@FindBy(xpath="//div[4]//div[1]//ul[1]//li[4]")
WebElement slider;
WebDriver driver;
public Slider(WebDriver driver) {
this.driver = driver;
//Inicializacion de los elementos con una espera impicita
PageFactory.initElements(new AjaxElementLocatorFactory(driver,20), this);
}
public void clickonSlider()
{ // 4 | click | css=.show #item-3 > .text |
// Hace click en Sliders
// //driver.findElement(By.cssSelector(".show #item-3 > .text")).click();
slider.click();
}
}
【问题讨论】:
-
"其他元素会收到点击:
标签: java selenium selenium-webdriver xpath css-selectors