我有个问题.我有这样的元素:
<a> id = someGenerated的元素Some:Same:0:name
<a> id = someGenerated的元素Some:Same:0:surname
<a> id = someGenerated的元素Some:Same:1:name
<a> id = someGenerated的元素Some:Same:1:surname
我需要CSS选择器来获取名称.问题是我不知道如何得到它.我试过a[id*='Some:Same']- 它返回了所有<a>元素.之后我可以获得id以name结尾的元素.但我不喜欢这个想法.我认为它可以用其他选择器完成.
我正在尝试选择一个选项进行网络测试.可以在此处找到一个示例:http://www.tizag.com/phpT/examples/formex.php
除了选择选项部分外,一切都很好.如何按值或按标签选择选项?
我的代码:
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using System.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;
class GoogleSuggest
{
static void Main()
{
IWebDriver driver = new FirefoxDriver();
//Notice navigation is slightly different than the Java version
//This is because 'get' is a keyword in C#
driver.Navigate().GoToUrl("http://www.tizag.com/phpT/examples/formex.php");
IWebElement query = driver.FindElement(By.Name("Fname"));
query.SendKeys("John");
driver.FindElement(By.Name("Lname")).SendKeys("Doe");
driver.FindElement(By.XPath("//input[@name='gender' and @value='Male']")).Click();
driver.FindElement(By.XPath("//input[@name='food[]' and @value='Chicken']")).Click();
driver.FindElement(By.Name("quote")).Clear();
driver.FindElement(By.Name("quote")).SendKeys("Be Present!");
driver.FindElement(By.Name("education")).SendKeys(Keys.Down + Keys.Enter); // working but that's not what i was looking for
// …Run Code Online (Sandbox Code Playgroud) 如何将Python的Selenium WebDriver中的所有cookie保存到txt文件中,然后再加载它们?该文档没有说明getCookies函数的任何内容.
当我使用WebDriver运行Chrome浏览器时,我在控制台上收到以下消息.请让我知道如何解决它.
"在端口22582上启动ChromeDriver(v2.10.267521)""仅允许本地连接."
这是我的示例代码:
public class Browserlaunch {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver_win32 \\chromedriver.exe");
WebDriver driver = new ChromeDriver() ;
driver.get("http://webdunia.com");
driver.close();
driver.quit();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在寻找类似于waitForElementPresent检查元素是否在我点击之前显示的东西.我认为这可以通过implicitWait,所以我使用以下内容:
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Run Code Online (Sandbox Code Playgroud)
然后单击
driver.findElement(By.id(prop.getProperty(vName))).click();
Run Code Online (Sandbox Code Playgroud)
不幸的是,有时它等待元素,有时候不等.我找了一会儿找到了这个解决方案:
for (int second = 0;; second++) {
Thread.sleep(sleepTime);
if (second >= 10)
fail("timeout : " + vName);
try {
if (driver.findElement(By.id(prop.getProperty(vName)))
.isDisplayed())
break;
} catch (Exception e) {
writeToExcel("data.xls", e.toString(),
parameters.currentTestRow, 46);
}
}
driver.findElement(By.id(prop.getProperty(vName))).click();
Run Code Online (Sandbox Code Playgroud)
它等了很久,但在超时前它必须等待5次,50秒.有点多.所以我把隐式等待设置为1秒,直到现在一切都好了.因为现在有些事情在超时之前等待10秒,但是其他一些事情在1秒之后会超时.
您如何覆盖代码中存在/可见元素的等待?任何提示都很明显.
我正在使用Selenium WebDriver 2.25.0进行多语言Web应用程序,主要测试页面内容(适用于阿拉伯语,英语,俄语等不同语言).
对于我的应用程序,根据性能更好,并确保它应该支持所有的浏览器(即IE 7,8,9,FF,Chrome等).
提前感谢您的宝贵建议.
我需要检查WebDriver中是否存在Alert.
有时它会弹出警报,但有时它不会弹出.我需要先检查警报是否存在,然后我可以接受或解除它,或者它会说:没有找到警报.
有人知道Selenium(最好是WebDriver)是否能够在启动Selenium客户端之前与已经运行的浏览器进行通信并采取行动?
我的意思是,如果Selenium能够在不使用Selenium Server的情况下与浏览器通信(例如可以手动启动Internet Explorer).
使用WebDriverSelenium 2.0a2,我无法检查元素是否可见.
WebDriver.findElement返回a WebElement,遗憾的是它没有提供isVisible方法.我可以通过使用WebElement.clear或WebElement.click两者抛出来解决这个问题ElementNotVisibleException,但这感觉很脏.
有更好的想法吗?
我使用了明确的等待,我有警告:
org.openqa.selenium.WebDriverException:元素在点(36,72)处不可点击.其他元素将收到点击:...命令持续时间或超时:393毫秒
如果我使用Thread.sleep(2000)我没有收到任何警告.
@Test(dataProvider = "menuData")
public void Main(String btnMenu, String TitleResultPage, String Text) throws InterruptedException {
WebDriverWait wait = new WebDriverWait(driver, 10);
driver.findElement(By.id("navigationPageButton")).click();
try {
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(btnMenu)));
} catch (Exception e) {
System.out.println("Oh");
}
driver.findElement(By.cssSelector(btnMenu)).click();
Assert.assertEquals(driver.findElement(By.cssSelector(TitleResultPage)).getText(), Text);
}
Run Code Online (Sandbox Code Playgroud)