我试着用
driver.findElement(By.cssSelector("....."));但它不起作用(不能与By一起使用FindElement )。你知道什么能取代它吗?我正在使用VisualStudio2019并用C#编写
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.)
}
}
}发布于 2022-07-28 16:09:59
可以使用xpath intro.asp。
对于特定的示例,您可以通过这样做来定位标题:
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");发布于 2022-07-28 18:51:56
根据By Class中的文档,符号如下:
CssSelector:通过其级联样式表(CSS)选择器获得查找元素的机制。您的有效代码行将是:
using OpenQA.Selenium;
var title_field = driver.FindElement(By.CssSelector("svg g rect:nth-child(20)"));参考文献
https://stackoverflow.com/questions/73154352
复制相似问题