首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Selenium findElement Visual中使用findElement(By.cssSelector(""))

如何在Selenium findElement Visual中使用findElement(By.cssSelector(""))
EN

Stack Overflow用户
提问于 2022-07-28 14:15:42
回答 2查看 108关注 0票数 -1

我试着用

代码语言:javascript
复制
driver.findElement(By.cssSelector("....."));

但它不起作用(不能与By一起使用FindElement )。你知道什么能取代它吗?我正在使用VisualStudio2019并用C#编写

代码语言:javascript
复制
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Interactions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace WebDriverTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            var driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://www.marketinginternetdirectory.com/submit.php");

            //Find form element to auto fill on form page - Right click on input->inspect
            var title_field = driver.FindElement(By.)

        }
    }
}
EN

回答 2

Stack Overflow用户

发布于 2022-07-28 16:09:59

可以使用xpath intro.asp

对于特定的示例,您可以通过这样做来定位标题:

代码语言:javascript
复制
var titleElement = driver.FindElement(By.XPath("//input[@name = 'TITLE']"));

// And if you want to go a step further you might after want to do something like this:
element.SendKeys("YOUR-TITLE");
票数 0
EN

Stack Overflow用户

发布于 2022-07-28 18:51:56

根据By Class中的文档,符号如下:

  • CssSelector:通过其级联样式表(CSS)选择器获得查找元素的机制。

您的有效代码行将是:

代码语言:javascript
复制
using OpenQA.Selenium;

var title_field = driver.FindElement(By.CssSelector("svg g rect:nth-child(20)"));

参考文献

Selenium C# Webdriver驱动程序教程

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73154352

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档