如何根据给定的HTML定位元素

问题描述 投票:0回答:1
<input value="Order (ESHOP)" class="btn" name="order_eshop" title="Order (ESHOP)" type="button" onclick="Sfdc.logServer('CUSTOM_URL_BUTTON', {id: '00b41000002iuj6', name: 'Order_ESHOP'}, Sfdc.Logging.LogLevel.INFO);
openIntegration('/servlet/servlet.Integration?scontrolCaching=1&amp;lid=00b41000002iuj6&amp;eid=a0863000007SV1q&amp;ic=1&amp;isdtp=vw&amp;linkToken=VmpFPSxNakF4T1MweE1TMHhNRlF5TVRvd09EbzBNaTQyT1RWYSx0eno3X1lSS1lOY1hORmtKb2ZvM3BxLFlXWmtNR0po', 'height=600,location=no,resizable=yes,toolbar=no,status=no,menubar=no,scrollbars=1', 1)">

我无法为此找到xpath。我在单个路径Order(ESHOP)上具有相同的元素。当我尝试使用索引时,找不到正确的xpath。

selenium selenium-webdriver xpath css-selectors webdriverwait
1个回答
0
投票

所需元素是启用了JavaScript的元素,因此要与该元素定位/交互,必须为elementToBeClickable()引入WebDriverWait,并且可以使用以下解决方案之一:

  • 使用CSS_SELECTOR

    WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.btn[name='order_eshop'][value='Order (ESHOP)'][title='Order (ESHOP)']")));
    
  • 使用XPATH

    WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='btn' and @name='order_eshop'][@value='Order (ESHOP)' and @title='Order (ESHOP)']")));
    
© www.soinside.com 2019 - 2024. All rights reserved.