Java 如何为html代码的linkText编写代码
我是selenium的新手,正在尝试为html代码编写linktext代码Java 如何为html代码的linkText编写代码,java,selenium,xpath,css-selectors,linktext,Java,Selenium,Xpath,Css Selectors,Linktext,我是selenium的新手,正在尝试为html代码编写linktext代码 <a href="repopulateUser.jsp?authAuthSessionId=7DD74346650647B7BA9ED08C1ABAE66D&roleId=bc95f1f2-9ccd-11e8-9a37-0050568817ef&ROLE=Programmer&ROLECODE=PROGRAMMER&roleGrpId=f4c11ca7
<a href="repopulateUser.jsp?authAuthSessionId=7DD74346650647B7BA9ED08C1ABAE66D&roleId=bc95f1f2-9ccd-11e8-9a37-0050568817ef&ROLE=Programmer&ROLECODE=PROGRAMMER&roleGrpId=f4c11ca7-9c1b-11e8-9a37-0050568817ef&moduleId=cb475927-7eb1-11e8-97d0-0050568817ef&studyId=null" class="labels">Programmer</a>
上面的代码不起作用,是不是出了什么问题?如果HTML中唯一标识了带有文本Programmer的元素,则linkText应该起作用。由于元素是已启用的元素,因此要在元素上单击(),您需要使用elementtobelickable()
,并且可以使用以下选项:
:linkText
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("Programmer"))).click();
:css选择器
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.labels[href^='repopulateUser']"))).click();
:xpath
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='labels' and starts-with(@href, 'repopulateUser')][text()='Programmer']"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='labels' and starts-with(@href, 'repopulateUser')][text()='Programmer']"))).click();