Java 如何为Selenium webdriver中选择的右键单击选项输入名称
我的场景是,我必须右键单击一个web元素并选择第二个选项,这将创建一个新的子位置,并且应用程序默认为新创建的子位置命名(示例默认值(1))。 我的目标是将默认名称更改为自定义名称,即将默认名称(1)更改为子名称(1) 我可以成功地右键单击,然后选择第二个选项,但无法将子位置重命名为自定义名称 html代码如下所示:Java 如何为Selenium webdriver中选择的右键单击选项输入名称,java,selenium-webdriver,Java,Selenium Webdriver,我的场景是,我必须右键单击一个web元素并选择第二个选项,这将创建一个新的子位置,并且应用程序默认为新创建的子位置命名(示例默认值(1))。 我的目标是将默认名称更改为自定义名称,即将默认名称(1)更改为子名称(1) 我可以成功地右键单击,然后选择第二个选项,但无法将子位置重命名为自定义名称 html代码如下所示: <ul class="rtUL"> <li class="rtLI rtFirst rtLast"> <div class="r
<ul class="rtUL">
<li class="rtLI rtFirst rtLast">
<div class="rtTop">
<ul class="rtUL">
<li class="rtLI rtLast">
<div class="rtBot rtSelected">
<span class="rtIn">Default (1)</span>
</div>
</li>
</ul>
</li>
</ul>
WebElement rootLocation = driver.findElement(By.xpath("//div[@id='Testlocation']//span[contains(text(),'RL')]"));
Actions action = new Actions(driver);
action.contextClick(RL).build().perform();
WebElement elementOpen = driver.findElement(By.linkText("Create Child"));
elementOpen.click();
请提供帮助。您可以在使用
JavascriptExecutor
成功右键单击后将默认名称更改为自定义名称,如下所示:-
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[contains(text(), 'Default (1)')]")));
((JavascriptExecutor)driver).executeScript("arguments[0].textContent = arguments[1]", el, "Child (1)")
希望在成功右键单击将新创建的子项的文本从
Default(1)
更改为child(1)
…)成功右键单击后,可以使用JavascriptExecutor
将默认名称更改为自定义名称,如下所示:-
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[contains(text(), 'Default (1)')]")));
((JavascriptExecutor)driver).executeScript("arguments[0].textContent = arguments[1]", el, "Child (1)")
希望在成功右键单击将新创建的子项的文本从
Default(1)
更改为child(1)
…)在frnd的帮助下,我得到了问题的解决方案
WebElement newLoc1 =driver.findElement(By.xpath("//span[contains(.,'Default (1)')]"));
Actions mAction = new Actions(driver);
mAction.moveToElement(newLoc1);
mAction.contextClick(newLoc1).build().perform();// This will do right click
driver.findElement(By.xpath("//span[contains(.,'Click to Rename')]")).click();//This will select the renaming option from the right click options
driver.findElement(By.xpath("//input[@value='Default (1)']")).sendKeys(Keys.HOME,Keys.chord(Keys.SHIFT,Keys.END),"newloc");//This will delete the Default name ie Default (1) and change the name to a new name ie newloc
`在朋友的帮助下,我找到了问题的解决方案
WebElement newLoc1 =driver.findElement(By.xpath("//span[contains(.,'Default (1)')]"));
Actions mAction = new Actions(driver);
mAction.moveToElement(newLoc1);
mAction.contextClick(newLoc1).build().perform();// This will do right click
driver.findElement(By.xpath("//span[contains(.,'Click to Rename')]")).click();//This will select the renaming option from the right click options
driver.findElement(By.xpath("//input[@value='Default (1)']")).sendKeys(Keys.HOME,Keys.chord(Keys.SHIFT,Keys.END),"newloc");//This will delete the Default name ie Default (1) and change the name to a new name ie newloc
`您能发布右键单击后出现的菜单html片段吗?我想,只是因为定位器的问题,它不工作。你们能发布右键点击后菜单的html片段吗?我想,仅仅因为定位器的问题,它不起作用。Gaurav,我使用了ur代码,它将默认(1)替换为子(1)(我看到在脚本运行时将其更改),但问题是当页面刷新时,名称仍然是默认的(1)。我试着做了构建和执行,但没有成功。现在代码是Actions action=newactions(驱动程序);WebDriverWait wait=新的WebDriverWait(驱动程序,10);WebElement el1=driver.findElement(By.xpath(//span[contains(text(),'Default(1)'))));((JavascriptExecutor)driver).executeScript(“参数[0].textContent=arguments[1]”,el1,“子(1)”;操作。单击(el1.build().perform()@reena是的,我知道它在运行时的变化只是为了测试目的,不会永久地影响。。。你想让更改永久生效吗???@reena你能和我分享一下手动更改默认名称的步骤吗?这就是为什么我可以为你提供永久生效的解决方案。Gaurav,我使用了你的代码,它将默认值(1)替换为子项(1)(我看到在脚本运行时对其进行更改)但问题是当页面刷新时,名称仍然作为默认值出现(1)。我试着做了构建和执行,但没有成功。现在代码是Actions action=newactions(驱动程序);WebDriverWait wait=新的WebDriverWait(驱动程序,10);WebElement el1=driver.findElement(By.xpath(//span[contains(text(),'Default(1)'))));((JavascriptExecutor)driver).executeScript(“参数[0].textContent=arguments[1]”,el1,“子(1)”;操作。单击(el1.build().perform()@reena是的,我知道它在运行时的变化只是为了测试目的,不会永久地影响。。。你想让更改永久生效吗???@reena你能告诉我这些步骤吗?如何手动更改默认名称?这就是为什么我可以为你提供永久生效的解决方案