情景:
登录www.flipkart.com并选择" Samsung"来自"电子"成功登录后。 现在,我需要滚动到页面的底部,从左侧,我需要点击可用性来选择"排除缺货选项"但 点击可用性,我收到消息
失败:Test_Samsung org.openqa.selenium.WebDriverException:元素在点(119,9)处不可点击。其他元素会收到点击:
//class for successful flipkart login public class Flipkart_Login { @FindBy(xpath="//a[text()='Log In']") WebElement Login_Click; @FindBy(xpath="//input[@class='_2zrpKA' and @type='text']") WebElement Enter_Email; @FindBy(xpath="//input[@class='_2zrpKA _3v41xv' and @type='password']") WebElement Enter_Pass; @FindBy(xpath="//button[@type='submit' and @class='_3zLR9i _1LctnI _36SmAs']") WebElement Login_Button; @FindBy(xpath="//span[text()='Please enter valid Email ID/Mobile number']") WebElement Blank_Email; @FindBy(xpath="//span[text()='Please enter Password']") WebElement Blank_Pass; public void Valid_Login() { Login_Click.click(); Enter_Email.sendKeys("abc@gmail.com"); Enter_Pass.sendKeys("abcde"); Login_Button.click(); } } //class for choosing Samsung from Electronics menu and clicking Availability public class Flipkart_Electronics_Samsung_Mobile { @CacheLookup @FindBy(xpath="//a[@title='Electronics']//span[text()='Electronics']") WebElement Electronics_Menu; @CacheLookup @FindBy(xpath="//a[@title='Samsung']//span[text()='Samsung']") WebElement Samsung_Mobile_Click; @CacheLookup @FindBy(xpath="//div[@class='_3QT2gR _1AgMas']//div[text()='Availability']") WebElement Availability; @CacheLookup @FindBy(xpath="//div[@class='_1p7h2j']") WebElement Exclude_Out_Of_Stock; public void Choose_Samsung_Mobile() { WebDriverWait wait = new WebDriverWait(driver, 30); Actions act = new Actions(driver); act.moveToElement(Electronics_Menu).perform(); act.click(wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@title='Samsung']//span[text()='Samsung']")))).build().perform(); WebElement Availability = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='_3QT2gR _1AgMas']//div[text()='Availability']"))); JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("arguments[0].scrollIntoView(true);", Availability); Availability.click(); } } //class which calls the methods from above two classes public class Flipkart_Electronics_Samsung_Search { WebDriver driver; @Test public void Test_Samsung() { driver = BrowserFactory.getBrowser("Firefox"); driver.get(DataProviderFactory.getConfig().getURL()); Flipkart_Login login = PageFactory.initElements(driver, Flipkart_Login.class); login.Valid_Login(); Flipkart_Electronics_Samsung_Mobile Samsung = PageFactory.initElements(driver, Flipkart_Electronics_Samsung_Mobile.class); Samsung.Choose_Samsung_Mobile(); } }
命令持续时间或超时:133毫秒
SELECT
答案 0 :(得分:2)
您可以尝试点击JavascriptExecutor
,因此您应该替换以下行: -
js.executeScript("arguments[0].scrollIntoView(true);", Availability);
Availability.click();
要
js.executeScript("arguments[0].click()", Availability);
答案 1 :(得分:1)
元素在点(119,9)处无法点击。其他元素将收到点击:命令持续时间或超时:133毫秒
它清楚地说,我们想要点击的元素在这种情况下会被其他元素div隐藏,这会接收到点击。
我认为UI的问题不应该隐藏元素,但你可以尝试一些事情: 1.从webdriver最大化浏览器窗口,看看元素是否仍然隐藏
driver.manage().window().maximize()
使用JavaScript点击元素
WebElement element = driver.findElement(By.<locator>);
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click()", element)