简体   繁体   English

如何使用Java Selenium Web驱动程序强制单击按钮

[英]How to click on a button with force using java selenium web driver

I am using selenium web driver with java. 我正在使用Java的Selenium Web驱动程序。

And developing automation for my app in facebook, so whenever I add my app for first time in facebook, it is asking for permissions with okay button 并为我的应用程序在Facebook中开发自动化,因此,每当我第一次在Facebook中添加我的应用程序时,它都会要求您单击“确定”按钮

I am trying to click on okay button with my code but that is not working. 我试图用我的代码单击“确定”按钮,但这不起作用。

Is there a better way to click on okay button using selenium web driver with java? 有没有更好的方法使用带有Java的Selenium Web驱动程序单击“确定”按钮?

What I tried is: 我试过的是:

1)driver.findElemenr(element).click();

2)Actions action = new Actions(driver);
  action.click(element)   

3)Actions action = new Actions(driver);
  action.moveToElement(element).click()

4)Actions action = new Actions(driver);
  action.KeyDown(element, Keys.ENTER);

Please let me know the reason before if you want to downvote my question 如果您想拒绝我的问题,请先告诉我原因

I think you are looking for isEnabled() method in Selenium. 我认为您正在Selenium中寻找isEnabled()方法。 What you can do is, after you click the button using webdriver you can check the status of the button and repeat the click process if the button is still enabled. 您可以做的是,使用webdriver单击按钮后,您可以检查按钮的状态,并在按钮仍处于启用状态时重复单击过程。

You just try with logic something like below. 您只需尝试以下类似的逻辑。

int i=0;
while(isElementPresent(button) && i<10)
{
        Thread.sleep(1000);
                driver.findElement(button).click();
                i++;
}

The above code will try to click on button until it present or i (int i)reached 10. (loop breaking point) 上面的代码将尝试单击按钮,直到它出现或i (int i)达到10。(循环断点)

You can find isElementPresent method implementation here . 您可以在此处找到isElementPresent方法实现。

you can try this, 你可以试试看

 WebDriverWait button = new WebDriverWait(driver,60);      
 button.until(ExpectedConditions.elementToBeClickable(element));
 button.click();

This will wait 60 secs for the button to be clickable,if condition (element is clickable) is met before 60 secs, well and good, button will be clicked, else an exception will be thrown... 这将等待60秒以使按钮可单击,如果在60秒之前满足条件(元素可单击),那么很好,将单击按钮,否则将引发异常。

ExpectedConditions class provides many useful methods . ExpectedConditions类提供了许多有用的方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Java在Selenium Web驱动程序中选择并单击单选按钮 - How to select and click on a radio button in selenium web driver with java 如何使用Java和Selenium Web驱动程序单击CTRL + P? - How to click CTRL+P using Java and selenium web driver? 如何在Java中使用Selenium Web驱动程序单击复选框? - How do I click on checkbox using selenium web driver in Java? 按钮未单击-使用Java的Selenium Web驱动程序 - Button not Clicking - Selenium Web Driver using java Selenium Web驱动程序,用于单击按钮 - Selenium web driver for button click 不能单击“搜索”按钮Selenium Web Driver Java - Not Able to click on “Search” button Selenium Web Driver Java 在Selenium Web驱动程序中使用Java脚本执行程序单击列表项 - click on list items using java script executor in selenium web driver 我们如何使用硒Web驱动程序在警告窗口中单击继续按钮 - how can we click continue button in warning window using selenium web driver 无法单击Web UI页面上单选按钮更改顺序的单选按钮Selenium Web Driver Java - Not able to click on Radio button where radio button change order on the web ui page Selenium Web Driver Java 如何使用Selenium Web Driver Java单击具有某些单词作为文本的href - How to click on one href which has certain words as text using selenium web driver java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM