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:
Related
I have tried a different method to input elements like
Here is xpath I used
By NameOfTheProperty=By.xpath("//fieldset/div/input[#name='name']");
By NameOfTheProperty=By.xpath("//div/input[#name='name']");
By NameOfTheProperty=By.xpath("//input[#name='name']");
Tried with Selenium Builder
WebElement element=driver.findElement(by);
Actions builder = new Actions(driver);
Action mouseOverHome = builder
.moveToElement(element)
.click().sendKeys(text).build();
mouseOverHome.perform();
Tried with
WebElement element=driver.findElement(by);
element.sendKeys(text);
None of the methods is working..I can not able to input text inside the field and It shows
Element not interactable
Here is the site
I hope someone help me to find out the solution..
Please check in the dev tools (Google chrome) if we have unique entry in HTML DOM or not.
Steps to check:
Press F12 in Chrome -> go to element section -> do a CTRL + F -> then paste the xpath and see, if your desired element is getting highlighted with 1/1 matching node.
xpath you should checks is :
//input[#name='name']
if it is unique, then you can use Javascript executor :
WebElement password_input = driver.findElemenet(By.xpath("//input[#name='name']"));
((JavascriptExecutor) driver).executeScript("arguments[0].setAttribute('value', 'password_should_be_written_here')", password_input)
personally I would use id's if the element has one.
"//*[#id='__BVID__104']"
Make sure you are waiting for the element to be ready.
WebDriverWait wait = new WebDriverWait();
wait.until(ExpectedConditions.elementToBeClickable(element));
If it then times out on wait.until(... then I've found that sometimes an element must first be clicked for it to be exposed.
If this is the case. You will have to inspect the element before it is clicked. Find it's xpath, and see if it changes when it is clicked. If so then create a webElement for that element and have Selenium first click it, before clicking the actual field/element.
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 want to click a button(to send a form)
<button class="form-button primary">Click here</button>
I find the element like this:
driver.findElement(By.xpath("//button[contains(text(),'Click here')]")).click;
On chorme is working and sending the form but in IE11 is not(sending the form).
To be clear, in IE is finding the element(or an element). But probably is not the correct element.
Addition info:
This is the only button with this text
I can probably find other ways to get this element , but if I rework this path I will need to change all the paths similar to this.
Selenium version:3.14
IE webdriver :3.14
There are several different ways of clicking on something using selenium. I would try using either a javascript click or an action click.
Javascript click:
WebElement element = driver.findElement(By.xpath("//button[contains(text(),'Click here')]"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
Action click:
Actions action = new Actions(driver);
WebElement element = driver.findElement(By.xpath("//button[contains(text(),'Click here')]"));
action.moveToElement(element).click().build().perform();
It's also possible that you are in the wrong frame while you are executing the click.
driver.switchTo.frame("Frame_ID");
You would be able to find the frame ID when you inspect the webpage.
If your usecase is to invoke click() you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:
xpath using className and text:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[#class='form-button primary' and text()='Click here']"))).click();
xpath using text:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[text()='Click here']"))).click();
xpath using contains():
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(., 'Click here')]"))).click();
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
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();