Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Xpath或CSS选择器使用Selenium单击按钮_Java_Html_Selenium_Xpath_Css Selectors - Fatal编程技术网

Java 使用Xpath或CSS选择器使用Selenium单击按钮

Java 使用Xpath或CSS选择器使用Selenium单击按钮,java,html,selenium,xpath,css-selectors,Java,Html,Selenium,Xpath,Css Selectors,在这里提问之前,我花了几个小时尝试使用各种选择器单击按钮,但似乎没有任何效果 WebElement add= driver.findElement(By.partialLinkText("+")); WebElement add= driver.findElement(By.xpath("/*[name()='svg']/*[name()='button']")); WebElement confirm = driver.findElement(By.xpath("//a[contains(@c

在这里提问之前,我花了几个小时尝试使用各种选择器单击按钮,但似乎没有任何效果

WebElement add= driver.findElement(By.partialLinkText("+"));
WebElement add= driver.findElement(By.xpath("/*[name()='svg']/*[name()='button']"));
WebElement confirm = driver.findElement(By.xpath("//a[contains(@class, 'IconButton-h85035-0 indexstyles__PlusButton')]"));
没有可用的示例具有与我正在使用的页面类似的html布局。 我不知道如何创建按钮的xPath。 如果您能提供有关如何创建xPath或CSS选择器的任何提示,我将不胜感激。不需要现成的解决方案,但请提供任何帮助,以了解如何引用该特定元素

这是加号按钮的代码:

<button data-testid="tselectionSpinbuttonPlus" type="button" tabindex="-1" aria-hidden="true" width="44px" height="44px" class="IconButton-h85035-0 indexstyles__PlusButton-sc-108enfc-3 bAZDfp">
    <svg viewBox="0 0 24 24" width="1.5em" height="1.5em" aria-hidden="true" focusable="false" class="BaseSvg-sc-9y47q5-0 PlusIcon___StyledBaseSvg-sc-11rza9m-0 VCaQT">
      <path d="M13 11V3h-2v8H3v2h8v8h2v-8h8v-2h-8z">
      </path>
    </svg>
 </button>
请尝试以下内容:


要定位/单击图元,可以使用以下任一方法:

CSS选择器:

xpath:

理想情况下,要定位/单击元素,您需要引导WebDriverWait使元素可单击,并且您可以使用以下任一定位策略:

CSS选择器:

xpath:

请尝试此驱动程序.findElementBy.cssSelectorbutton[data testid='tselectionSpinbuttonPlus']。单击
WebElement add= driver.findElement(By.partialLinkText("+"));
        Actions ac1 = new Actions(driver);
                    ac.clickAndHold(add).build().perform();
driver.findElement(By.cssSelector("button[data-testid='tselectionSpinbuttonPlus']")).click();
driver.findElement(By.xpath("//button[@data-testid='tselectionSpinbuttonPlus']")).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button[data-testid='tselectionSpinbuttonPlus']"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@data-testid='tselectionSpinbuttonPlus']"))).click();