Tag: selenium

Selenium偶尔会出现UnreachableBrowserException

我试图通过在Java中使用Selenium来访问多个网站。 偶尔,我得到一个UnreachableBrowserException 。 我已经读过很多关于这个错误的线索,但似乎有很多不同的错误原因。 当我尝试访问新页面时,我得到的错误大约是1%的时间,我发现事件之间没有任何相似之处。 我目前正在使用Firefox,但我也尝试过Internet Explorer并遇到过类似的错误。 我一次只打开一个页面并尝试使用相同的窗口并在尝试访问另一个页面之前完全退出驱动程序,无论哪种方式仍然出现错误。 重要的是要注意我并不总是得到这个错误有时我的代码可以运行而不会发生这种情况。 这是错误消息: Jan 12, 2015 10:39:40 PM org.apache.http.impl.execchain.RetryExec execute INFO: I/O exception (java.net.SocketException) caught when processing request to {}- http://127.0.0.1:7055: Permission denied: connect Jan 12, 2015 10:39:40 PM org.apache.http.impl.execchain.RetryExec execute INFO: Retrying request to {}->http://127.0.0.1:7055 Jan 12, 2015 10:39:40 PM org.apache.http.impl.execchain.RetryExec execute INFO: I/O exception (java.net.SocketException) caught […]

使用Selenium和AutoIt通过远程桌面自动化

我想自动执行需要通过远程桌面连接的某些任务。 我将分享我写到的代码。 public class MainClass { static WebDriverWait wait; static WebDriver driver; public static void main(String args[]) { driver = new HtmlUnitDriver(true); driver.get(“https://mysite”); WebElement submit_element=driver.findElement(By.id(“Log_On”)); driver.findElement(By.id(“Enter user name”)).sendKeys(“my_username”); driver.findElement(By.name(“passwd”)).sendKeys(“my_password”); submit_element.click(); driver.findElement(By.id( “folderLink_0”)).click(); driver.findElement(By.id( “folderLink_2”)).click(); driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS); System.out.println(driver.getPageSource()); driver.findElement(By.id(“idCitrix.M”)).click(); System.out.println(driver.getPageSource()); } } 代码行 `driver.findElement(By.id(“idCitrix.M”)).click();` 在新窗口中打开远程桌面。 这条线 `System.out.println(driver.getPageSource());` is retrieving the same code in both places. 我相信这不能仅由Selenium完成。 […]

在selenium webderiver中从IDE / Console获取用户输入

我想从用户输入中获取密钥(发送密钥)我应该如何实现它? driver.findElement(By.xpath(“.//*[@id=’vehicleNum’]”)).sendKeys(“1121”);

使用selenium给出错误在java中获取隐藏元素

当我选择值隐藏其显示错误为: 线程“main”中的exceptionorg.openqa.selenium.NoSuchElementException:无法定位元素:{“method”:“部分链接文本”,“选择器”:“vehicle-make”} 这是我的代码: package section5.advWays.locatingObjects; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.Select; public class CusXPathUsingAtt1 { public static void main(String[] args) throws InterruptedException { // TODO Auto-generated method stub WebDriver wd = new FirefoxDriver(); wd.manage().window().maximize(); Thread.sleep(5000); wd.get(“http://www.tirerack.com/content/tirerack/desktop/en/homepage.html”); Select SelectMakedropdown = new Select(wd.findElement(By.id(“vehicle-make”))); SelectMakedropdown.selectByVisibleText(“BMW”); Select YearSelectDropdown = new Select(wd.findElement(By.id(“vehicle-year”))); YearSelectDropdown.selectByVisibleText(“2011”); Select VehicleSelectDropdown = new Select(wd.findElement(By.id(“vehicle-model”))); […]

Selenium WebDriver在切换之前获取当前帧

通过切换某个iFrame,我有一个自定义操作来查找元素。 它使用以下本机操作: driver.switchTo().frame(requested_frame)目前我在切换到确切的iframe之前每次切换回默认内容。 现在我需要通过以下scnario来提高它的性能: 检查当前内容/框架 如果requested_frame=currentFrame则无需切换 if requested_frame=null然后切换到默认值(如果currentFrame=default则再次无需切换) if requested_frame!=null && requested_frame!=currentFrame然后切换到默认值,并切换到requested_frame帧。 所以我现在需要的是获得当前帧。 有什么方法可以得到它吗?

selenium找不到合适的方法(ExpectedCondition )

这是有线问题! 我导入的项目是100%(几个月前)工作的,今天我用依赖项导入了它, WebDriverWait存在一个问题 这是我的代码: WebDriverWait driverWait = new WebDriverWait(driver, 10000); driverWait.until(ExpectedConditions.presenceOfElementLocated(By.id(“saveBut1”)));//here’s the issue 这是错误: no suitable method found for until(ExpectedCondition) method FluentWait.until(Predicate) is not applicable (argument mismatch; ExpectedCondition cannot be converted to Predicate) method FluentWait.until(Function) is not applicable (cannot infer type-variable(s) V (argument mismatch; ExpectedCondition cannot be converted to Function)) where V,T are type-variables: V […]

如何在集线器中注册节点后启动远程webdriver?

我正在尝试启动remoteWebdriver,因为我已经逐步创建了一个集线器,然后我在其上添加了一个节点。 这很好。我执行时的问题: Thread.currentThread().join(); 程序停止执行,如果我删除此行,我会收到错误。 try{ String strIP = “localhost”; GridHubConfiguration config = new GridHubConfiguration(); config.setTimeout(30000000); config.setPort(4444); config.setHost(strIP); Hub hub = new Hub(config); hub.start(); RegistrationRequest req = new RegistrationRequest(); req.setRole(GridRole.NODE); Map nodeConfiguration = new HashMap(); nodeConfiguration.put(RegistrationRequest.PROXY_CLASS, DefaultRemoteProxy.class.getName()); nodeConfiguration.put(RegistrationRequest.MAX_SESSION, 5); nodeConfiguration.put(RegistrationRequest.PORT, 5555); nodeConfiguration.put(RegistrationRequest.HOST, 4444); nodeConfiguration.put(RegistrationRequest.AUTO_REGISTER, true); nodeConfiguration.put(RegistrationRequest.REGISTER_CYCLE, 5000); nodeConfiguration.put(RegistrationRequest.HUB_HOST, “localhost”); nodeConfiguration.put(RegistrationRequest.HUB_PORT, 4444); nodeConfiguration.put(“remoteHost”, “http://” + strIP + […]

从Eclipse执行AutoIt代码

我正在使用Selenium WebDriver进行自动化,并希望处理浏览器身份validation窗口。 我知道Selenium不支持这个,但我可以使用AutoIt。 我们必须与客户共享我们的代码,因此可以从Eclipse管理AutoIt代码吗? 这是代码: WinWaitActive(“Authentication Required”, “”, “120”) If WinExists(“Authentication Required”) Then Send(“username{TAB}”) Send(“password{Enter}”) EndIf 从Eclipse运行AutoIt.exe的代码: Runtime.getRuntime().exec(“C:\\NewAutoIT.exe”); 有没有办法从Eclipse管理AutoIt代码?

Selenium – 如何计算表中的行数?

我有一个行数为“n”的表。 我需要数数,怎么办? 示例: – 我的表格如下所示。 Type Balance Date received Date returned Payment method Amount General Default 10/01/2013 08:53:20 Cash $ 10.00 HTML of my table looks like this. is table title row and are the entries done by the user. Everytime the user add the new entry, the count will increase and display a message […]

使用selenium自定义Chrome webdriver以保存文件,而不会在下载时提示保存或丢弃文件

我正在尝试使用chlenium使用chrome作为我的浏览器使用chromedriver自动下载文件。 当我尝试下载exe文件时,它提示我“这种类型的文件可能会损害您的计算机,丢弃或保存它”。 我希望它无需任何提示即可下载。 我已经研究过以下几个解决方案: chromeOptions = webdriver.ChromeOptions() prefs = {“browser.helperApps.alwaysAsk.force” :False,”browser.helperApps.neverAsk.saveToDisk” : “application/octet-stream”} chromeOptions.add_experimental_option(“prefs”,prefs) browser = webdriver.Chrome(executable_path=//path//to//chrome_driver, chrome_options=chromeOptions) 但这并没有帮助它仍然提出了提示。 非常感谢任何帮助。 谢谢,