这段代码没有按预期工作......请帮忙 [英] This code didnt work as expected...please help
问题描述
package testCode;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
公共类Testcode2 {
public static void main(String [] args)
{
System.setProperty(webdriver.gecko.driver ,C:// Program Files(x86)// geckodriver-v0.11.1-win64 // geckodriver.exe);
WebDriver driver = new FirefoxDriver();
String URL =http://www.demoqa.com;
driver.get(URL);
driver.findElement(By.xpath(.//* [@ id ='menu-item-374'] / a))。click();
driver.navigate()。back();
driver.navigate()。forward();
driver.navigate()。to(URL);
driver.navigate()。refresh();
driver.quit();
}
}
在测试此代码时,返回,转发,执行和刷新命令都没有用,它关闭了浏览器......等等问题使用代码
Firefox版本是45.0.2,当我检查代码行时我发现在点击提到的XPATH链接后,它没有点击返回,转发链接但是(URL)和刷新代码在一秒钟内执行。任何建议!!!!!!!!!!!!
我尝试过:
我尝试使用implicitwait函数来检查在等待几秒后它是否会执行我提到的那些任务,否则它们没有工作。
< blockquote>这段代码需要一段时间才能执行,因为它是多线程的。使用计时器回调来执行每个代码段。一些等待大约2到10秒的人将是我的第一个猜测。
一些例子如何运行和使用超时。
我已经尝试过implict等待函数,但它也没有用。
package testCode; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class Testcode2 { public static void main(String[] args) { System.setProperty("webdriver.gecko.driver","C://Program Files (x86)//geckodriver-v0.11.1-win64//geckodriver.exe"); WebDriver driver = new FirefoxDriver(); String URL = "http://www.demoqa.com"; driver.get(URL); driver.findElement(By.xpath(".//*[@id=’menu-item-374′]/a")).click(); driver.navigate().back(); driver.navigate().forward(); driver.navigate().to(URL); driver.navigate().refresh(); driver.quit(); } }
While testing this code, back, forward, to and refresh commands didnt work and it closed the browser…..any issues with the code
Firefox version is 45.0.2 and when i checked the code line wise i found that after clicking the XPATH link mentioned, it does not click back, forward links but the to (URL) and refresh code is executed in a flash of a second. Any suggestions !!!!!!!!!!!!
What I have tried:
I tried the implicitwait function to check if after waiting for few secs it will perform those tasks which i have mentioned, didnt work otherwise.
This code need sometime to execute, because it is multithreading. Work with timer callbacks to execute each code piece. Some waiting around 2 to 10 seconds would be my first guess.
Some examples how to run and work with timeouts.
I have already tried implict wait function but it didnt work either.
这篇关于这段代码没有按预期工作......请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!