在官方W3c webdirver文档中,明确指出位置策略是:
State Keyword
CSS selector "css selector"
Link text selector "link text"
Partial link text selector "partial link text"
Tag name "tag name"
XPath selector "xpath"
Run Code Online (Sandbox Code Playgroud)
但是,Selenium的电线协议允许:
class name
css selector
id
name
link text
partial link text
tag name
xpath
Run Code Online (Sandbox Code Playgroud)
在理论中,Selenium的文档已经过时,"真实"的故事在新的规范文档中.然而...
我在最新的Chrome自己的Webdriver上运行了一些测试,我可以确认这一点,name并且class name两者都有效; 但是,它们不符合规格.
我记得在Chromium问题上阅读他们只会实现官方的Webdriver规范.
现在:我知道通用答案,其中"规格并不总是100%遵循"等.但是,我想知道的是:
javascript selenium google-chrome chromium chrome-web-driver
我正在编写一个简单的 selenium 测试,它发送一个不正确的字母字符串,然后提交并返回和错误。然后我想发送一串字母,但这次使用正确的字符串,所以它被接受了。
我在测试中面临的问题是第一组字符串已经在文本字段中,所以当我去提交第二组时,它将它添加到已经提交的第一个字符串中。
所以我本质上需要做的是发送第一个字母字符串然后需要清除文本字段然后发送第二个字母字符串。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Interactions;
using System.Threading;
namespace Exercise1
{
class RunPath
{
static void Main()
{
IWebDriver webDriver = new ChromeDriver();
webDriver.Navigate().GoToUrl("https://energy.gocompare.com/gas-electricity");
webDriver.Manage().Window.Maximize();
String title = webDriver.Title;
String expectedTitle = "Utilities from Go Compare";
if (title.Contains(expectedTitle))
{
Console.WriteLine("Tile is matching with expected value");
}
else
{
Console.WriteLine("Tile is matching with expected value");
}
webDriver.FindElement(By.XPath(".//button[@type = 'submit']")).Click();
webDriver.FindElement(By.XPath(".//input[@type = 'text']")).SendKeys("W30PN#");
webDriver.FindElement(By.XPath(".//button[@type = …Run Code Online (Sandbox Code Playgroud) clear()在这种情况下不起作用。我追加后追加。
searchForMovie.clear()无法运作...我也曾尝试传送
CTRL + 'a',然后传送DELETE。同样,我得到的只是附件...
for movie in allMissing:
time.sleep (10)
searchForMovie = WebDriverWait (driver, 10).until \
(EC.presence_of_element_located ((By.CSS_SELECTOR, "#search-text")))
searchForMovie.send_keys (movie)
# click
enter = WebDriverWait (driver, 10).until \
(EC.presence_of_element_located ((By.CSS_SELECTOR, "#search-submit")))
driver.execute_script ("arguments[0].click()", enter)
# clear the search text box
searchForMovie = WebDriverWait (driver, 10).until \
(EC.presence_of_element_located ((By.CSS_SELECTOR, "#search-text")))
searchForMovie.clear()
Run Code Online (Sandbox Code Playgroud) selenium css-selectors python-3.x selenium-webdriver webdriverwait