Tag: selenium webdriver

Selenium WebDriver:等待加载JavaScript的复杂页面

我有一个Web应用程序来测试Selenium。 页面加载时会运行很多JavaScript。 这段JavaScript代码编写得不是很好,但我无法改变任何东西。 因此,等待元素出现在DOM中并使用findElement()方法不是一种选择。 我想在Java中创建一个通用函数来等待页面加载,可能的解决方案是: 从WebDriver运行JavaScript脚本,并将document.body.innerHTML的结果存储在字符串变量body 。 将body变量与先前版本的body 。 如果它们相同则设置增量计数器notChangedCount否则将notChangedCount设置为零。 等待一个小时(例如50毫秒)。 如果页面没有改变一段时间(例如500毫秒),那么notChangedCount >= 10然后退出循环,否则循环到第一步。 你认为这是一个有效的解决方案吗?

java.lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置

这是我的代码: package Basics; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class invokegoogle { public static void main(String[] args) { // TODO Auto-generated method stub System.setProperty(“Webdriver.chrome.driver”, “C:\\Users\\sravani\\Desktop.exe”); WebDriver driver=new ChromeDriver(); driver.get(“http://qaclickacademy.com”); } } 出现以下错误: Exception in thread “main” java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. […]

如何使用Selenium WebDriver从隐藏元素中读取文本?

我试图从隐藏的 读取示例String 1000 ,如下所示: 1000 我知道WebElement.getText()不能用于Selenium 2(WebDriver)中的隐藏元素,所以我搜索了解决方案( 就像这个 ),显然以下代码应该可以工作: WebElement hiddenDiv = seleniumDriver.findElement(By.id(“hidden_div”)); String n = hiddenDiv.getText(); // does not work (returns “” as expected) String script = “return arguments[0].innerText”; n = (String) ((JavascriptExecutor) driver).executeScript(script, hiddenDiv); 但它对我不起作用,变量n总是以null 。 我究竟做错了什么?

Selenium中的pageLoadTimeout无效

我在Java中使用selenium使用下面的代码。 我正在添加4秒的pageLoadTimeout,但是,驱动程序继续等待,直到加载完整的页面。 有帮助吗? System.setProperty(“webdriver.gecko.driver”, System.getProperty(“user.home”) + “\\Desktop\\geckodriver.exe”); FirefoxBinary b = new FirefoxBinary(new File(System.getProperty(“user.home”) + “\\desktop\\Mozilla Firefox\\firefox.exe”)); FirefoxOptions options = new FirefoxOptions().setBinary(b); driver = new FirefoxDriver(options); //driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(4, TimeUnit.SECONDS); driver.get(“https://www.booking.com/hotel/in/the-taj-mahal-palace-tower.html?label=gen173nr-1FCAEoggJCAlhYSDNiBW5vcmVmaGyIAQGYATG4AQbIAQzYAQHoAQH4AQKSAgF5qAID;sid=338ad58d8e83c71e6aa78c67a2996616;dest_id=-2092174;dest_type=city;dist=0;group_adults=2;hip_dst=1;hpos=1;room1=A%2CA;sb_price_type=total;srfid=ccd41231d2f37b82d695970f081412152a59586aX1;srpvid=c71751e539ea01ce;type=total;ucfs=1&#hotelTmpl”); List facilitySectionList = driver.findElements(By.className(“facilitiesChecklistSection”));

Selenium – 通过URL进行基本身份validation

在我的Selenium-Test (使用chromedriver-2.24 )中,我尝试使用以下语句通过基本身份validation访问我的网页: WebDriver driver = …; driver.get(“http://admin:admin@localhost:8080/project/”); 但谷歌Chrome在控制台中给出了以下警告: [弃用]其URL包含嵌入凭据(例如https://user:pass@host/ )的子资源请求被阻止。 有关详细信息,请参阅https://www.chromestatus.com/feature/5669008342777856 。 在标记的链接中提到支持被删除: 在子资源请求中删除对嵌入式凭据的支持。 (已删除) 我现在的问题是,还有另一种从Selenium进行基本身份validation的方法吗? 注意 :这没有帮助: 如何使用Java处理Selenium Webdriver中的HTTP Basic Auth头?

用显式等待替换隐式等待(selenium webdriver&java)

如何用显式替换这个隐式等待? driver = new ChromeDriver(function); 。driver.manage()deleteAllCookies(); driver.manage()。timeouts()。implicitlyWait(10,TimeUnit.SECONDS); 这在Before Method中使用。 我能够替换代码中的所有Thread.sleep(),但我不知道该怎么做。

Selenium WebDriver在线程“main”中抛出exceptionorg.openqa.selenium.ElementNotInteractableException

测试场景:尝试捕获并测试Gmail登录。 当前输出: Mozilla实例打开。 输入用户名,但WebDriver代码未输入密码。 System.setProperty(“webdriver.gecko.driver”, “C:\\Users\\Ruchi\\workspace2\\SeleniumTest\\jar\\geckodriver-v0.17.0-win64\\geckodriver.exe”); FirefoxDriver varDriver=new FirefoxDriver(); varDriver.get(“http://gmail.com”); WebElement webElem= varDriver.findElement(By.id(“identifierId”)); webElem.sendKeys(“error59878@gmail.com”); WebElement nextButton=varDriver.findElement(By.id(“identifierNext”)); nextButton.click(); varDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); WebElement wePass=varDriver.findElement(By.cssSelector(“.rFrNMe.P7gl3b.sdJrJc.Tyc9J”)); wePass.sendKeys(“test1”);

如何使用FirefoxProfile通过Firefox浏览器自动下载?

我正在使用selenium java,我需要下载pdf文件,我提到了这个 , 这也是这里的答案,但似乎没有什么在我的情况下工作。 是因为设置了一个新的firefox驱动程序实例,即System.setProperty(“webdriver.firefox.bin”, “D:\\FFF\\firefox.exe”); ? 我被困在这里。但是,当我手动点击MIME对话框上的保存文件时,它正确地保存到我的自定义位置,我的下载链接代码也驻留在另一个java类和下面的代码中,但我使用相同的驱动程序在这个类中声明,下面是我的代码, FirefoxProfile profile = new FirefoxProfile(); //Set Location to store files after downloading. profile.setPreference(“browser.download.folderList”, 2); profile.setPreference( “browser.download.manager.showWhenStarting”, false ); profile.setPreference(“browser.download.dir”, “D:\\WebDriverDownloads”); profile.setPreference(“pdfjs.disabled”, true); profile.setPreference(“browser.helperApps.neverAsk.saveToDisk”, “application/pdf”); System.setProperty(“webdriver.firefox.bin”, “D:\\FFF\\firefox.exe”); driver = new FirefoxDriver(profile);

如何解决Selenium webdriver中的ElementNotInteractableException?

在这里,我有我的代码的图像和我的错误的图像。 任何人都可以帮我解决这个问题吗?

如何使用Java处理Selenium WebDriver中的新窗口?

这是我的代码: driver.findElement(By.id(“ImageButton5”)).click(); //Thread.sleep(3000); String winHandleBefore = driver.getWindowHandle(); driver.switchTo().window(winHandleBefore); driver.findElement(By.id(“txtEnterCptCode”)).sendKeys(“99219”); 现在我有下一个错误: 线程“main”中的exceptionorg.openqa.selenium.NoSuchElementException:无法找到id == txtEnterCptCode的元素(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:404毫秒。 有任何想法吗?