无法使用Selenium Java自动执行Amazon.com的退出操作。

huangapple go评论64阅读模式
英文:

Cant automate Amazon.com signout using Selenium Java

问题

我正在尝试做一个简单的Selenium Java自动化,以实现对"登录并退出Amazon.com网站"的自动化操作。我可以使用元素定位技术(如XPath和CSS选择器)进行登录。但是在退出时,我遇到了"ElementNotInteractable"异常。

以下是我尝试的代码(仅发布退出代码段):

WebElement element1 = driver.findElement(By.xpath("//header/div[@id='navbar']/div[@id='nav-belt']/div[3]/div[1]/a[1]/span[1]"));
element1.click();
driver.findElement(By.xpath("//a[@id='nav-item-signout']")).click();

我已经尝试了上述代码段,使用不同的元素定位技术,如CSS选择器等,但是没有成功。请问是否有其他方法可以在下拉菜单中找到并点击"退出"链接。谢谢。

英文:

I'm trying to do a simple selenium java automation for automating "sign in and sign out of amazon.com site". I'm able to sign in using element locator techniques, like XPath and CSS selector. But for signout, I'm thrown with ElementNotInteractable exception.

Below is the code that I tried(posting the code segment of signout alone).

WebElement element1 = driver.findElement(By.xpath("//header/div[@id='navbar']/div[@id='nav-belt']/div[3]/div[1]/a[1]/span[1]"));
element1.click();
driver.findElement(By.xpath("//a[@id='nav-item-signout']")).click();

I have tried the above code segment with different element locator techniques like CSS selector and etc, but no luck.
Kindly suggest if I can find and click the sign-out link in the flyout menu by any other method.
Thanks.

答案1

得分: 1

以下是您要翻译的代码部分:

WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement element1 = driver.findElement(By.xpath("//header/div[@id='navbar']/div[@id='nav-belt']/div[3]/div[1]/a[1]/span[1]"));
element1.click();
ele2 = driver.findElement(By.xpath("//a[@id='nav-item-signout']"));
wait.until(ExpectedConditions.elementToBeClickable(ele2));
ele2.click();

请注意,这是您提供的代码的中文翻译部分。

英文:

You can try below code in which explicit wait is implemented so it will wait for the element to click

WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement element1 =driver.findElement(By.xpath("//header/div[@id='navbar']/div[@id='nav- 
       belt']/div[3]/div[1]/a[1]/span[1]"));
element1.click();
ele2=driver.findElement(By.xpath("//a[@id='nav-item-signout']"))   
wait.until(ExpectedConditions.elementToBeClickable(ele2));
ele2.click();

答案2

得分: 0

代替click()方法,尝试以下代码:

WebElement element1 = driver.findElement(By.xpath("//header/div[@id='navbar']/div[@id='nav-belt']/div[3]/div[1]/a[1]/span[1]"));
element1.sendKeys(Keys.RETURN);
driver.findElement(By.xpath("//a[@id='nav-item-signout']")).sendKeys(Keys.RETURN);

而且你也可以尝试使用ENTER键代替RETURN。

英文:

Instead of the click() method try this :

      WebElement element1 = driver.findElement(By.xpath("//header/div[@id='navbar']/div[@id='nav-belt']/div[3]/div[1]/a[1]/span[1]"));
  element1.sendKeys(Keys.RETURN);
driver.findElement(By.xpath("//a[@id='nav-item-signout']")).sendKeys(Keys.RETURN);

And instead of RETURN you can also try ENTER

答案3

得分: 0

以下是翻译好的内容:

你可以尝试下面的代码,其中实现了鼠标悬停在菜单上,然后你可以点击退出。

WebElement ele = driver.findElement(By.id("nav-link-accountList-nav-line-1"));
Actions action = new Actions(driver);
action.moveToElement(ele).perform();
driver.findElement(By.xpath("//*[@id='nav-item-signout']/span")).click();
英文:

You can try below code in which mover hover is implemented so it will hover the menu then you can click for sign-out.

WebElement ele = driver.findElement(By.id("nav-link-accountList-nav-line-1"));
Actions action = new Actions(driver);
action.moveToElement(ele).perform();
driver.findElement(By.xpath("//*[@id='nav`enter code here`-item-signout']/span")).click();

huangapple
  • 本文由 发表于 2020年10月3日 14:55:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/64181543.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定