Tag: selenium

使用webdriver找不到元素

有一个网络元素: A B 因为它有onchange ,我无法选择该选项。 我的代码是这样的: new Select(driver.findElement(By.id(“sel”))).selectByValue(“1”); 但它无法奏效。 是否有可能使它工作?

需要在没有Thread.sleep的情况下编写selenium代码

我写了以下代码登录网站“qtpselenium.com” 。 如果我在其间给出Thread.sleep以使代码执行暂停一段时间,下面的代码工作正常。 如果我评论Thread.sleep,代码不能按预期工作。 我试图使用selenium的隐式和显式等待使驱动程序等待元素可见,但代码只能在我使用Thread.sleep时按预期工作。 有没有办法,我可以使用下面的代码,而不使用Thraed.Sleep语句。 在selenium代码中使用Thread.sleep语句是不好的做法? import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.FluentWait; public class QTPSelenium { public static WebDriver driver = null; public static void main(String[] args) throws InterruptedException { System.setProperty(“webdriver.gecko.driver”,”C:\\Eclipse\\Drivers\\geckodriver.exe”); driver = new FirefoxDriver(); driver.get(“http://qtpselenium.com/”); driver.findElement(By.xpath(“.//*[@class=’btn btn-default member_login’]”)).click(); Thread.sleep(10000); driver.findElement(By.xpath(“(//button[@type=’submit’])[3]”)).click(); Thread.sleep(10000); driver.findElement(By.id(“email”)).sendKeys(“Some Email ID”); driver.findElement(By.id(“login-password”)).sendKeys(“Some Password”); driver.findElement(By.xpath(“html/body/main/div[2]/div/div/div[1]/div/div/div/form/button”)).click(); […]

测试通过但行动没有发生selenium webdriver + testng

我是selenium webdriver的新手,我在IE 8上使用2.31版本,testng 6.8和防火测试。我在这个方案中编写我的测试:我有测试类,我有使用testng @Test注释的方法。 它看起来像这样: @Test(description=”click Save Button “, dependsOnMethods = { “edit form” }) public void clickSaveButton(ITestContext context) { page.clickSaveButton(driver); } 然后,正如你所看到的,我有一个页面类,我存储元素id,xpath等。它像这样lokks: public void clickSaveButton(WebDriver driver){ Configuration.clickfoundElement(By.id(conf.get(“saveButton”)), driver); } conf是表示属性文件的对象。 最后我有Configuration类,我在这里做了一些思考: public static void clickfoundElement(By by, WebDriver driver){ int attempts = 0; while(attempts < 10) { try { driver.findElement(by).click(); break; } catch(NoSuchElementException e) […]

Java – Selenium WebDriver – 如何检查文件下载对话框是否可见? (不下载只有可见性)

是否可以使用Selenium WebDriver或任何其他Java库检查IE中的文件下载对话框是否可见? 我不想下载该文件。 我无法validation对话框的可见性。 此外,我无法关闭对话框。 有帮助吗?

如何在java代码中设置代理配置

我正在尝试用Java编写一个类来启动我的Selenium Server,以防它由于某种原因而关闭。 我在这里找到了很好的帮助: http : //www.testingexcellence.com/how-to-start-selenium-server-with-java-code/ 我看到一些配置参数可以使用类RemoteControlConfiguration和setPort,setLogOutFileName,setTimeoutInSeconds等方法设置。 问题是我的Selenium Server以这种方式连接到代理: java -jar selenium-server.jar -Dhttp.proxyHost=my.proxy.com -Dhttp.proxyPort=8080 不幸的是,我还没有找到如何把它放到java代码中。 我的问题是:是否可以在java中设置proxyHost和proxyPort值? 谢谢你的时间=) } {灵丹妙药

如何使用不同的包管理Selenium项目代码(如页面对象模型/关键字驱动程序框架)

作为自动化的第一次用户,我正在寻找与自动化项目组织和其他相关内容相关的帮助。 任何人都可以和我一起分享样本项目。 我可以编写脚本,但我无法管理java中的代码。 建议我任何网站的最佳方式。

如何找到下拉列表的选定选项?

我们如何在Selenium Webdriver中找到Dropdown的选定选项? 我试过了 – WebElement element = driver.findElement(By.xpath(locator1)); Select select = new Select(element); List SO = select.getAllSelectedOptions(); String S = SO.toString(); System.out.println(S); 返回WebElements,如 – [[[[[FirefoxDriver: firefox on XP (c388e8a8-09d5-41b9-b086-0278c639d8b1)] -> xpath: .//*[@id=’city’]]] -> tag name: option]] 我想找到被选中的选项?

为什么Selenium找不到图形可见的元素

我正在使用Selenium测试在firefox浏览器上运行的应用程序,有时当我想点击带有Selenium的按钮时,它只是找不到它。 我发现这很奇怪,因为我可以用眼睛看到这个元素。 我已经尝试了多种方法,适用于其他例子: wait.until(ExpectedConditions.visibilityOfElementLocated(通过)) wait.until(ExpectedConditions.presenceOfElementLocated(通过)); (我在路径变量中使用xpath,我确信他是正确的) 设置implictlyWait驱动程序 放入Thread.sleep(1000) 然后,我在这里发布,因为我不明白为什么Selenium看不到在浏览器上显示的元素。 一个重要的信息可能会帮助你给我一个正确的答案是html DOM是由javascript事件触发的websocket动态生成的。 编辑1: Delete 我想要访问的元素。 我使用xpath来做到这一点。 它不在iframe元素中。 要访问一个元素我做了这个方法,应该找到并点击它给出参数中的xpath: public void findAndClick(String xpath) { By by = By.xpath(xpath); //wait.until(ExpectedConditions.presenceOfElementLocated(by)); wait.until(ExpectedConditions.visibilityOfElementLocated(by)); driver.findElement(by).click(); } 编辑2: 这里特定的xPath:// div [2] / div / div / div /按钮我发现它使用的是Selenium插件。 编辑3: 我得到的例外是 StaleReferenceElementException:在缓存中找不到元素 – 也许页面在查找后发生了变化。 我去了解这个例外的页面 ,它说: The element has been deleted entirely. The […]

无法在“chrome:// downloads /”页面找到网络元素

我正在使用Java和Selenium为Chrome编写测试。 有时我需要进入chrome://downloads/并单击CLEAR ALL按钮。 我可以到达页面 RemoteWebDriver driver = (RemoteWebDriver) driverChrome; driver.executeScript(“window.open();”); Thread.sleep(500); tabs = new ArrayList(driverChrome.getWindowHandles()); driverChrome.switchTo().window(tabs.get(1)); Thread.sleep(500); driverChrome.get(“chrome://downloads/”); 但我无法点击按钮,无论我使用什么xpath,都说no such element

如何在TestNg类之间传递WebDriver的单个实例

我无法在网上的任何地方找到一个不同的答案。 我有多个TestNg类来运行测试,BrowserFunctions,登录,搜索,过滤(测试亚马逊的实践)。 我还有一个BrowserLauncher类,它根据浏览器名称和testng.xml文件返回相应的webdriver。 BrowserFunctions.java public class BrowserFunctions { BrowserLauncher bl = new BrowserLauncher(); WebDriver driver; StringBuilder sb = new StringBuilder(); @BeforeSuite public void initialioseBrowser() { driver = bl.launchBrowser(“Firefox”); } @Parameters({ “URL” }) @BeforeSuite public void invokeURL(String URL) { driver.get(URL); } @AfterSuite public void closeBrowser() { driver.close(); } Login.java public class Login { BrowserLauncher bl = […]