Tag: selenium

如何在黄瓜jvm场景之间传递变量和值

我有两个场景A和B.我在一个变量中存储’A’场景的字段输出的值。 现在我必须在场景’B’中使用该变量。 如何在Cucumber Java中将变量及其值从一个场景传递给另一个场景

我可以同时在不同的端口上运行selenium服务器吗?

我看到这篇文章关于如何在2个不同的端口上运行selenium web驱动器服务器。 我试过这样做: java -Dwebdriver.chrome.driver=./chromedrive -jar selenium-server-standalone-2.44.0.jar -port 4445 java -Dwebdriver.chrome.driver=./chromedrive -jar selenium-server-standalone-2.44.0.jar -port 4444 并运行在端口4445上调用服务器的代码 但我得到这个例外: rond-macpro:selenium eladb$ java -Dwebdriver.chrome.driver=./chromedrive -jar selenium-server-standalone-2.44.0.jar -port 4445 17:26:14.740 INFO – Launching a standalone server 17:26:14.780 INFO – Java: Oracle Corporation 24.76-b04 17:26:14.781 INFO – OS: Mac OS X 10.9.5 x86_64 17:26:14.793 INFO – v2.44.0, with Core v2.44.0. […]

selenium – 如何在属性中按文本单击日历日期

我遇到的问题是我不想在单击17或18时指定绝对xpath – 而是希望能够通过指定文本来单击。 但链接文本在html中查找或href属性,并且我有 属性,我需要帮助如何通过某种方式指定文本来点击它。 以下是驻留在表中的示例html代码: 17 18 这是我的selenium代码: //click the calendar button driver.findElement(By.xpath(“//*[@id=’btnTradeDate’]”)).click(); //go through the calendar table to navigate through each cell WebElement dateWidget = driver.findElement(By.id(“transactionGridControls”)); List rows=dateWidget.findElements(By.tagName(“tr”)); List columns=dateWidget.findElements(By.tagName(“td”)); for (WebElement cell: rows){ //Select 17th Date if (cell.getText().equals(“17”)){ cell.findElement(By.linkText(“17”)).click(); //need help on this break;

如何使用Selenium(Java)在浏览器中禁用JavaScript?

在我的function自动化中,我需要在浏览器中禁用JavaScript并运行流程。 如何禁用JavaScript? 试过firefox和Chrome的DesiredCapabilities。 DesiredCapabilities dc = new DesiredCapabilities(); dc.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, false) 和 DesiredCapabilities dc = new DesiredCapabilities(); dc.setJavascriptEnabled(false); 对于firefox,尝试过1)为firefox设置配置文件 2)添加附加组件 – noScript.xpi 3)profile.setPreference(“javascript.enabled”,false); 4)通过UI,尝试将标志 – “about:config”中的“javascript.enabled”更改为false。 在这里,打开firefox并给出“about:config”警告 – “这可能会使您的保修失效!”。 有一个按钮 – “我会小心的,我保证!” id – warningButton。 应单击此按钮以继续。 要单击此按钮,请使用driver.findElement(By.id(“warningButton”))。click(); 但它不起作用。 以上所有选项均无效。 任何建议都会有所帮助。

如何通过webdriver测试输入字段function的屏蔽

您好我想测试密码字段是否屏蔽了密码字段中输入的字符串。 我怎么能通过webdriver测试它。 我试过下面的事情: package unitTest.JUnitTestCases; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class PasswordTest { @Test public void test() { WebDriver driver=new FirefoxDriver(); driver.manage().window().maximize(); driver.get(“http://docs.sencha.com/extjs/4.2.1/extjs-build/examples/form/adv-vtypes.html”); WebElement username=driver.findElement(By.id(“textfield-1014-inputEl”)); username.sendKeys(“admin”); System.out.println(username.getText()); WebElement password=driver.findElement(By.id(“textfield-1015-inputEl”)); password.sendKeys(“admin”); System.out.println(password.getAttribute(“textContent”)); //WebElement login=driver.findElement(By.id(“login”)); } } 在这里,我输入密码字段中的某个值,并尝试获取在该字段中输入的文本,以便我将检查它是否被屏蔽。 TIA!

如何在使用java单击链接时打开新窗口

if(driver.findElement(By.xpath(“xxx”)).isDisplayed() != True){ // if clicked in the above condition is True then it has to be opened in a new window driver.findElement(By.xpath(“xxx”)).click(); } else { System.out.println(“element not present — so it entered the else loop”); }

无法阅读VR Path Registry – Selenium Webdriver

我正在尝试使用Selenium和java执行测试用例,但页面没有完全加载,我在eclipse控制台中收到此消息: 无法读取VR Path Registry 这条消息是什么意思? 这是代码 FirefoxDriver driver = new FirefoxDriver(); try { driver.get(url); WebDriverWait wait = new WebDriverWait(driver, 10); driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(idName))); … 控制台: 1513781293556 Marionette INFO Enabled via –marionette Unable to read VR Path Registry from C:\Users\jo\AppData\Local\openvr\openvrpaths.vrpath [Parent 12932, Gecko_IOThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346 Unable to read VR Path […]

Selenium UnreachableBrowserException – Java

System.setProperty(“webdriver.chrome.driver”,”D:/chromedriver.exe”); WebDriver driver = new ChromeDriver(); driver.navigate().to(“https://link”); driver.findElement(By.cssSelector(“#username”)).sendKeys(“id”); driver.findElement(By.cssSelector(“#password”)).sendKeys(“pass”); driver.findElement(By.cssSelector(“#clientName”)).sendKeys(“name”); driver.findElement(By.cssSelector(“#submitButton”)).click(); System.out.println(“Okay !”); 我为Chrome驱动程序设置了属性。 当我运行它时会出错。 (下面)我搜索了很多,但没有找到任何解决方案。 Starting ChromeDriver 2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab) on port 10589 Only local connections are allowed. Exception in thread “main” org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Build info: version: […]

selenium:使用cssSelector看不到元素,而使用xpath可见

我试过java代码: driver.findElement(By.cssSelector(“input.only-numbers.ltr”)).sendKeys(“111”); 我收到一个错误: 线程“main”中的exceptionorg.openqa.selenium.ElementNotVisibleException:元素不可见 但当我将代码更改为xpath时,这项工作就完美了 driver.findElement(By.xpath(“html/body/section[10]/div/div[2]/form/div[1]/input”)).sendKeys(“111”); HTML代码: איפוס סיסמה תעודת זהות 为什么会发生这种情况?如何使用cssSelector修复?

如何通过selenium webdriver中的sendKeys传递变量?

我想在下面的程序中通过sendKeys传递浮点变量’f’。有人请让我知道吗? 截至目前,它正在投掷 “WebElement类型中的方法sendKeys(CharSequence …)不适用于参数”。 码: public static String isEditable(String s1) { f=Float.parseFloat(s1); System.out.println(f); boolean bool=webDriver.findElement(By.xpath(“expression”)).isEnabled(); if(bool) { if((f6)) { error=”Value must be between 0.00% and 6.00%”; System.out.println(error); } else { webDriver.findElement(By.xpath(“”expression”)).sendKeys(f); } } else { error=”Please enter a valid Number”; } return error; }