Trying to send any data to "from text field" on below link.
https://flights.msn.com/en-in/flight-search
Code is below:
WebDriverWait wait= new WebDriverWait(driver,20);
WebElement dropdown=driver.findElement(By.xpath("(//a[#href='/en-in/weather'])[1]"));
dropdown.click();
driver.findElement(By.xpath("(//a[#href='/en-in/travel'])[1]")).click();
driver.findElement(By.xpath("//li/a[#href='https://flights.msn.com/en-in/flight-search']")).click();
//WebElement from=wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("(//div[#class='place-selector js-place-selector'])[1]")));
WebElement from=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[#id='search']/div[1]/div[3]/div")));
//js.executeScript ("document.getElementById('from').focus();");
//from.click();
Thread.sleep(3000);
//from.sendKeys(Keys.BACK_SPACE);
from.sendKeys("Delhi");
from.sendKeys(Keys.ENTER);
Getting error:
Error:org.openqa.selenium.WebDriverException: unknown error: cannot focus element
you need to send the word Delhi to a element then wait until the list appear next click the li contain it.
WebElement origin = driver.findElement(By.cssSelector("div.js-originplace a"));
Actions actions = new Actions(driver);
actions.moveToElement(origin).click().sendKeys("Delhi");
actions.build().perform();
WebElement from = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//ul//li[contains(., 'Delhi')]")));
from.click()
I think you have not enter proper xpath for from variable, you have forgot to enter index on last div i have shown below let see it helps if this not work then please print or paste all console error or information
WebElement from=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[#id='search']/div[1]/div[3]/div")));
WebElement from=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[#id='search']/div[1]/div[3]/div[index_no]")));
I think might be because of elementToBeClickable will you just change and let me know change it by presenceOfElement let see if its work or not
Related
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.
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();
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
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();
I am coding a selenium webdriver test in Java. I need the test to click on a "Yes" button in chrome that does not have an id or name.
I cannot find the element to click on the button that only has "Yes" as its unique identifier. There is also a "No" button.
I have tried to find the WebElement using xpath, classname and I have tried findElements function. Nothing succeeds.
This is the HTML:
<span class="ui-btn-inner">
<span class="ui-btn-text popup-anchor-text">Yes</span>
</span>
I have tried:
WebElement yesBtn = browser.findElement(By.xpath("//div[#class='ui-btn-text popup-anchor-text']/span"));
WebElement yesBtn = browser.findElement(By.xpath("//span[.='Yes']"));
WebElement yesBtn = browser.findElement(By.xpath("//div[contains(text(), 'Yes')]"));
WebElement yesBtn = browser.findElement(By.xpath("//button[#class='ui-btn-text popup-anchor-text' and span='Yes']"));
WebElement yesBtn = browser.findElement(By.xpath("//div[#class='ui-btn-text popup-anchor-text' and span='Yes']"));
yesBtn.click();
List<WebElement> yesBtn = browser.findElements(By.className("ui-btn ui-shadow ui-btn-corner-all ui-btn-up-a"));
yesBtn.get(0).click();
Error message:
NoSuchElementException; no such element. Unable to locate element.
The correct XPath locator would be:
//span[text()='Yes']
Just in case you can go for normalize-space() function:
//span[normalize-space()='Yes']
If this doesn't help:
Make sure that the span doesn't belong to an iframe, otherwise you will have to switch to the iframe before attempting to locate the element.
driver.switchTo().frame("your-frame");
Make sure to use WebDriverWait class just in case the element is not immediately available so WebDriver would perform several find attempts with polling interval
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Yes']")));
Try out //span[#class='ui-btn-inner']/descendant::span[contains(text(), 'Yes')]. It should help out.
Task:
search FAA in search box :
I have tried this:-
webdriver.select_tabs(search.btnSearch);
Thread.sleep(3000);
WebElement searchbox = driver.findElement(By.id("search-text"));
Actions builder = new Actions(driver);
Actions seriesOfActions = builder.moveToElement(searchbox).click().sendKeys(searchbox, "FAA");
seriesOfActions.perform();
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id=\"search-text\"]")));
element.sendKeys("FAA");
element.sendKeys(Keys.ENTER);
webdriver.enter_key(search.txtSearch, Keys.ENTER);
webdriver.enter_Text(search.txtSearch, "FAA");
webdriver.enter_key(search.txtSearch, Keys.ENTER);
Got this error:-
org.openqa.selenium.ElementNotVisibleException: element not visible
Use below xpath :
(//input[#id='search-text'])[2]
and use like :
driver.findElement(By.xpath("(//input[#id='search-text'])[2]")).sendKeys("FAA");
When you find by this id in console it is giving two elements and first one is not visible but second one is the actual input box.
By definition, Selenium interacts with the browser like a real user would. A real user would not be able to type into a textbox/editbox which is hidden. Either you need to change the visibility of the input, re-evaluate why you need to interact with a hidden element, or use javascript executor to set the value of the input, something like this:
driver.executeScript("arguments[0].value='" + textToEnter + "'", element);
To send a character sequence to the search field on the website https://faatoday.com/ you need to induce WebDriverwait to wait for the search icon to be clickable and then again induce WebDriverWait once again for the desired element to be clickable and then send the character sequence as follows:
Code Block:
driver.get("https://faatoday.com/");
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div#navbarNav span.sicon-holder.fabutton#searchicon>i.fa.ssearch.fa-search.fa-lg#sicons"))).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[#id='navbarNav']//input[#class='search-text form-control mr-sm-2' and #id='search-text']"))).sendKeys("FAA");
Browser Snapshot:
When I am trying to execute below code its giving me exception as:-org.openqa.selenium.ElementNotVisibleException: element not visible
WebElement elem = newDriver.findElement(By.name("loginId"));
elem.get(0).clear();
elem.get(0).sendKeys("asd");
even though element is present.
For more details see the below image.
I am trying to access input box below account label but its giving me exception as element is not visible.
I already used Actions tag and JavascriptExecutor
Any suggestions.
The interested element is inside an iframe:
So, before, you have to switch to the iframe:
WebElement iframe= driver.findElement(By.id("alibaba-login-box"));
driver.switchTo().frame(iframe);
If you want to go "out" the iframe:
driver.switchTo().defaultContent();
The entire code:
WebElement iframe= driver.findElement(By.id("alibaba-login-box"));
driver.switchTo().frame(iframe);
WebElement elem = driver.findElement(By.id("fm-login-id"));
elem.clear();
elem.sendKeys("asd");
//when you want to return to the defaultContent
driver.switchTo().defaultContent();
I am trying to locate an element and click on that element to go to the other page but the element is not getting clicked but it is not showing any errors or warning. Its just highlighting the element but it is not getting clicked
i am using the following
WebDriverWait wait2 = new WebDriverWait(driver,10);
Thread.sleep(10000);
WebElement elements = driver.findElement(By.id("menuItem_Permissions"));
Actions action = new Actions(driver);
action.moveToElement(elements).click().perform();
Try Using Implicit Wait and a bit of this trick
WebElement element = new WebDriverWait( driver, 10 )
.until( ExpectedConditions.elementToBeClickable
(By.id("menuItem_Permissions")));
WebElement wait = new WebDriverWait(driver,
10).until(ExpectedConditions.visibilityOf(element));
Actions scrollToElement = new Actions(driver);
scrollToElement.moveToElement(wait).perform();
element.click();
In your action string you want to use .build() - so adding it like this.
action.moveToElement(elements).click().build().perform();
And as #Faiz has mentioned, you have declared a WebDriverWait command but its not being called anywhere, not from what you have posted. Avoid the Thread.sleep is where possible. Thats not causing the issue however.
You shouldn't need to use an actions builder for one element, just try using elements.click();