admin管理员组文章数量:1295304
nothing is working well for it. suggest me better option. due to fast speed i can't detect execution in better way. here is my code:
public static void main(String[] args) {
//**********************************open ff
WebDriver driver=new FirefoxDriver();
//**************************************maximize ff
driver.manage().window().maximize();
Logger log = Logger.getLogger("devpinoyLogger");
driver.get("");
log.debug("entring username");
driver.findElement(By.xpath("//*[@id='UserName']")).sendKeys("rpadmin");
log.debug("entering password");
driver.findElement(By.xpath("//*[@id='Password']")).sendKeys("Password123");
log.debug("Clicking login");
driver.findElement(By.xpath("//*[@id='loginForm']/form/div[4]/div/input")).click();
log.debug("Clicking voucher");
driver.findElement(By.xpath("html/body/nav/div[2]/div[2]/ul/li[2]/a")).click();
log.debug("selecting search_voucher");
List<WebElement> elements=driver.findElements(By.id("VoucherType"));
//elements.get(0).click(); //GV
elements.get(1).click(); //GC
//elements.get(2).click();//AP
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id='main']/form[2]/div[2]/input[4]")).click();
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id='main']/div[1]/span/a")).click();
}
}
nothing is working well for it. suggest me better option. due to fast speed i can't detect execution in better way.
nothing is working well for it. suggest me better option. due to fast speed i can't detect execution in better way. here is my code:
public static void main(String[] args) {
//**********************************open ff
WebDriver driver=new FirefoxDriver();
//**************************************maximize ff
driver.manage().window().maximize();
Logger log = Logger.getLogger("devpinoyLogger");
driver.get("http://navvitistgvm.cloudapp/nvrppluginassist/Account/Login");
log.debug("entring username");
driver.findElement(By.xpath("//*[@id='UserName']")).sendKeys("rpadmin");
log.debug("entering password");
driver.findElement(By.xpath("//*[@id='Password']")).sendKeys("Password123");
log.debug("Clicking login");
driver.findElement(By.xpath("//*[@id='loginForm']/form/div[4]/div/input")).click();
log.debug("Clicking voucher");
driver.findElement(By.xpath("html/body/nav/div[2]/div[2]/ul/li[2]/a")).click();
log.debug("selecting search_voucher");
List<WebElement> elements=driver.findElements(By.id("VoucherType"));
//elements.get(0).click(); //GV
elements.get(1).click(); //GC
//elements.get(2).click();//AP
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id='main']/form[2]/div[2]/input[4]")).click();
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id='main']/div[1]/span/a")).click();
}
}
nothing is working well for it. suggest me better option. due to fast speed i can't detect execution in better way.
Share asked Nov 20, 2015 at 20:12 user5580179user5580179 7- Are you saying that your program is too fast and asking how you can slow it down? – Kenney Commented Nov 20, 2015 at 20:14
- 1 can you add a bit more detail to your question so I can better answer for you. What actually is the issue you have? – cconolly Commented Nov 20, 2015 at 20:15
- yes. due to that sometimes it gives no such element found exception. – user5580179 Commented Nov 20, 2015 at 20:15
- @cconolly slenium web driver clicks or entering every detail fast. i need to slow down whole process. – user5580179 Commented Nov 20, 2015 at 20:17
- you want every mand to run with more time between them? You say your getting no such element exceptions suggesting the test runs a bit too early rather than too fast. Which elements get this exception? – cconolly Commented Nov 20, 2015 at 20:19
6 Answers
Reset to default 3For u who is looking for help in 2020, i remend this page: https://www.selenium.dev/documentation/en/webdriver/waits/
i used the Explicit wait method! helped aloot
So this isn't a direct answer to your question, slowing down the process, but this is an answer to the problem I think your having.
You don't need the steps to run slower, but what you do need is to make sure that you dont run any steps untill the page has properly loaded.
You can use WebDriverWait
and visibilityOfElementLocated
to solve this issue.
I've added a couple of lines to your code
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
import org.openqa.selenium.support.ui.WebDriverWait;
public static void main(String[] args) {
//**********************************open ff
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 30);
//**************************************maximize ff
driver.manage().window().maximize();
Logger log = Logger.getLogger("devpinoyLogger");
driver.get("http://navvitistgvm.cloudapp/nvrppluginassist/Account/Login");
// driver.get should block the execution of following steps untill the
// page has loaded so this line below in theory shouldnt be needed.
// Try it in your code and see for yourself
// Wait till the username field is visible.
wait.until(visibilityOfElementLocated(By.xpath("//*[@id='UserName']"))));
log.debug("entring username");
driver.findElement(By.xpath("//*[@id='UserName']")).sendKeys("rpadmin");
log.debug("entering password");
driver.findElement(By.xpath("//*[@id='Password']")).sendKeys("Password123");
log.debug("Clicking login");
driver.findElement(By.xpath("//*[@id='loginForm']/form/div[4]/div/input")).click();
// I assume here is your other issue, when clixking login the view changes
// and your running this next mand before the view has properly refreshed.
// add a wait here as well.
wait.until(visibilityOfElementLocated(By.xpath("html/body/nav/div[2]/div[2]/ul/li[2]/a")));
log.debug("Clicking voucher");
driver.findElement(By.xpath("html/body/nav/div[2]/div[2]/ul/li[2]/a")).click();
log.debug("selecting search_voucher");
List<WebElement> elements=driver.findElements(By.id("VoucherType"));
//elements.get(0).click(); //GV
elements.get(1).click(); //GC
//elements.get(2).click();//AP
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id='main']/form[2]/div[2]/input[4]")).click();
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id='main']/div[1]/span/a")).click();
}
}
If you really want the code to execute "slower" something which I wouldn't remend (how slow do you make it?) much better would be to explicitly test using the method I showed you above and only adding waits where you know you need to (eg page/view loading as a result of an action)
An approach would be to wrap actions and add a timeout eg:
public void waitAndClick(Xpath) {
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath(Xpath)).click();
}
Give the first approach a try though, its a much better solution.
If you're getting no such element exceptions after you do some action and before another then use an explicit wait (http://www.seleniumhq/docs/04_webdriver_advanced.jsp).
Please don't add a bunch of sleeps!!
You need to use fluent wait for a page to load or after every click event wait for a particular element to load and then perform certain selenium api calls:
You can find docs on how Fluent Wait of selenium works over here https://selenium.googlecode./git/docs/api/java/org/openqa/selenium/support/ui/FluentWait.html
You can try Thread.sleep(3000) (for 3sec) if implicity and explicity does not work as expected..
i hope below link clarifies on execution speed, setSpeed in Selenium WebDriver using Ruby
I was stumbling against the same in my own code. I tried in my application these codes from the selenium API:
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath")));
wait.until(visibilityOfElementLocated(By.xpath(xpath)));
It worked a way better, but still I was getting errors like xpath is not located. So i figured out those waiting methods from Selenium were somehow too fast or my elements didn't showed up on time.
Now with this code it really works fine for my application:
//extra waiting due to the limitiations of selenium, selenium sometimes loads too fast
Random ran = new Random();
//The integer x is now the random number that has a possible oute of 800-1200.
int x = ran.nextInt(401) + 800;
try {
Thread.sleep(x);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
本文标签: javascripthow to fix selenium web driver is moving too fastStack Overflow
版权声明:本文标题:javascript - how to fix selenium web driver is moving too fast? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741615661a2388511.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论