Tag: selenium webdriver

Selenium使用JavaScript或获取元素时出错

使用Seleneium 2.25,我遇到了很多问题。 我正在尝试从我的计算机(本地/客户端)在远程计算机(服务器)上使用Selenium Remote Driver。 但是,当我尝试使用DesiresCapabilities.Htmlunit()时,它将找到元素,但它表示它们不可见。 我完全被这个难过了。 我不确定为什么它可以找到,但后来不可见。 所以我试着用一些JavaScript来强制它。 它返回并抛出一个错误,说网页在加载页面之前无法执行javascript。 当我做了一个牵连的等待,它发现了它正在等待的元素时,这怎么可能? DesiredCapabilities iecapa = DesiredCapabilities.HtmlUnit(); iecapa.IsJavaScriptEnabled = true; driver = new RemoteWebDriver(new Uri(“http://:4444/wd/hub”), iecapa); IJavaScriptExecutor jQuery = ((IJavaScriptExecutor)(driver)); addressElement = (IWebElement)jQuery.ExecuteScript(“return document.GetElementByName(‘searchAddress’)”); 所以,如果有人想帮助我,我将不胜感激! 谢谢! http://sofzh.miximages.com/c%23/4jseleniumhtmluniterrorj/ 那就是错误。 StackOverflow不会让我在这里发布。 =(

当webdriver控件在框架中时,返回jQuery.active“)== 0正在等待提供的最大时间,然后引发exception

基于下面的#19#,请问Selenium等待加载Ajax内容 – 通用方法 我正在使用J Script和J Query代码来检查是否所有Ajax调用都已完成。 在这里我使用两个相同的页面并且它每次都工作正常但是当webdriver控件在框架中时返回jQuery.active“)== 0正在等待提供的最大时间然后引发exception。 请参阅下面收到的例外情况 预期条件失败:等待XXXclassNAME $$ Lambda $ 102/944794273 @ 1b96f242(尝试60秒,间隔为200 MILLISECONDS) 你可以帮我解决这个问题,当控件是否在框架内时,这个登录是否不起作用?

Selenium WebDriver MoveToElement – 隐藏元素,hover和toggleClass

Selenium WebDriver:2.35。 FireFox:25.0 我想将鼠标移到div上,这会导致隐藏的图像变得可见,然后单击图像。 我已经在这里 , 这里 , 这里和其他人阅读了这些post。 一般的答案是做一些forms的事情: action.moveToElement(we).moveToElement(webdriver.findElement(By.xpath(“/expression-here”)).click().build().perform(); 但是,这在以下示例中不起作用: HTML: 使用Javascript / jQuery的: $( document ).on( ‘hover’, ‘#bb_testDiv’, function () { $( this ).find( ‘.bb_matchImgTest’ ).toggleClass( ‘bb_standardHidden’ ); } ) $( document ).on( ‘click’, ‘.bb_matchImgTest’, function () { alert(‘here’); } ) CSS: .bb_standardHidden { visibility:hidden; } C#测试代码: IWebElement testDiv = WebDriver.FindElement( By.Id( […]

如何从angularjs应用程序的输入字段中获取文本()

我有我的DOM如下, 我想从上面的输入标记getText() 。 我尝试了下面的方法,但由于这是一个JSapplication我无法getText 。 尽管文本在DOM不可见,但在UI对用户可见。 List values = driver.findElements(By.xpath(“//input[@ng-model=’controller.model.value’]”)); for(int i=0;i<values.size();i++) { String theTextIWant = values.get(0).getAttribute("ng-model"); System.out.println(theTextIWant); } 下面是我执行上述代码时得到的输出。 controller.model.value controller.model.value controller.model.value 从输出中我可以说它只是获取属性“ng-model”中存在的值,而不是UI可见的实际文本。 请告知如何获取UI可见的文本。 预期文本: 9161 韦斯利 乔特

Selenium – 将“WebElement”转换为Javascript或JQuery对象的通用方法

我有一个简单的WebElement,我想在我的对象上执行一系列(一个或多个)JS / JQuery类型的操作。 大多数情况下这很简单,我只需获取对象的ID,将其传递到“ExecuteScript”函数中,并且中提琴效果很好: RemoteWebDriver driver = …; var element = driver.FindElementByXPath(“…”); //Or any other type of lookup driver.ExecuteScript(@”$(‘#” + element.GetAttribute(“id”) + “‘).”DoSomeStuff…;”); 20%这根本不起作用,因为该项目没有ID。 当然,有许多方法可以在Selenium中查找项目以及在jQuery或Javascript中查找项目的许多方法,但它们并不总是映射,虽然可以在jQuery中构造一个可以查找Selenium对象的查询,方法对于每种对象类型都不一样。 搜索它似乎大多数人使用“id”方法(例如: 1,2,3 )。 你可以用相反的方式做到这一点 。 另一个想法是在jQuery中访问它之前给每个元素在selenium中提供一个唯一的ID,但它看起来不会起作用,因为设置它需要使用Javascript或jQuery。 我还没有找到一种方法来为每个元素做这个普遍的事情,如何做到这一点?

使用以前使用Selenium 2选择器选择的Jquery选择一个元素

我选择了Selenium WebElement,例如: WebElement element = webDriver.findElement(By.xpath(‘//div/span[@id=’test’]’)); 如果我不知道如何找到这个元素,我如何用JQuery选择相同的元素? 我所拥有的只是webDriver实例和元素实例。 用“伪代码”说,我想要这样的东西: webDriver.executeScript(“$(” + element.getUniqueSelector() + “).attr(‘id’, ‘test2’)”); /编辑 我得到了我的答案: 来自Selenium 2 / WebDriver的Id的jQuery元素选择器

Selenium Webdriver JQUERY

我是Selenium WebDriver的新手,我正在学习Selenium WebDriver,了解如何使用jQuery选择器来处理元素而不是XPath表达式,ID等… 你能否帮我提供链接,在那里我可以找到有关如何在Selenium WebDriver中使用jQuery的基本信息?

无法使用javascript执行HTML5拖放以进行Selenium WebDriver测试

为了实现Selenium测试的拖放,我提到了http://elementalselenium.com/tips/39-drag-and-drop有人提到使用javascript(来自https://gist.github.com/rcorreia) / 2362544 )处理拖放。 我按原样实现了它并且它有效。 但就我而言,我为源和目标元素提供了动态xpath。 为了实现这一点,我尝试使用以下代码: package org.test.selenium; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class HTML5DragAndDrop { WebDriver driver = null; @BeforeClass public void setUp(){ System.out.println(System.getProperty(“user.dir”)); String chromeDriver = System.getProperty(“user.dir”)+ File.separator + “drivers” + File.separator + “chromedriver.exe”; System.setProperty(“webdriver.chrome.driver”, chromeDriver); […]

Selenium wait.until检查ajax请求完成是抛出错误

在使用Python的selenium Webdriver中,我想等待Ajax请求完成(jquery库)。 我使用Selenium的wait.until()函数。 单击submitJquery按钮后开始Ajax请求。 wait.until(self.driver.execute_script(“return jQuery.active == 0”)) 但我得到以下错误: E ====================================================================== ERROR: test_MahsumAkbasNet_Pass (__main__.TestClass) ———————————————————————- Traceback (most recent call last): File “D:\xxx\src\unittestpackage\JavaScriptExec.py”, line 24, in test_MahsumAkbasNet_Pass wait.until(self.driver.execute_script(“return jQuery.active == 0”)) File “C:\Python27\lib\site-packages\selenium\webdriver\support\wait.py”, line 66, in until value = method(self._driver) TypeError: ‘bool’ object is not callable ———————————————————————- Ran 1 test in 14.449s FAILED (errors=1) 完整的代码是: # […]

如何在量角器中为元素存在与否创建条件

我正在使用Protractor JS。 该网站是用Angular JS编写的。 所以我有一个拨动开关。 我注意到,当你关闭或打开时,切换开关的值从true变为false,false变为true。 我正在尝试在Protractor访问我的页面时创建一个条件,当它看到切换开关’关闭’它将打开它’。 如果拨动开关已经“打开”,它将首先将其关闭,然后再将其打开。 我提出了这个代码,但由于某种原因它无法正常工作: if( expect(element(By.id(‘toggle-switch’)).element(By.css(‘[value=”false”]’)).isDisplayed()) ) { element(By.id(‘toggle-switch’)).click(); console.log(‘in the if’) } else{ element(By.id(‘toggle-switch’)).click(); browser.sleep(3000); element(By.id(‘toggle-switch’)).click(); console.log(‘in the else’) } 此代码似乎仅适用于if语句。 出于某种原因,它永远不会去其他地方。 这是我收到的错误: NoSuchElementError:找不到使用locator的元素:By.cssSelector(“[value = \”false \“]”) 那么我试过了 .isPresent()而不是.isDisplayed()我不再收到上述错误,但由于某些原因,当使用.isPresent()时,它总是转到if语句并且只运行那个,而不是else语句。 没有显示错误。 如果有更好的方法请告诉我。 这似乎非常有限,因为无法在此框架中创建适当的条件。