Autocomplete seleniumHow do you disable browser Autocomplete on web form field / input tag?jQuery autocomplete tagging plug-in like StackOverflow's input tags?Removing input background colour for Chrome autocomplete?How to take screenshot with Selenium WebDriverGet HTML Source of WebElement in Selenium WebDriver using PythonNot able to click on the drop down elementUnable to print the Text associated with the li taghow to select the dropdown valueNot able to click on link obtain using findElements methodI am trying to hit on next button in gmail login screen without entering email id , this is basically to test negative scenario
Does Doodling or Improvising on the Piano Have Any Benefits?
How to preserve electronics (computers, iPads and phones) for hundreds of years
What is Cash Advance APR?
When were female captains banned from Starfleet?
Is there a nicer/politer/more positive alternative for "negates"?
Microchip documentation does not label CAN buss pins on micro controller pinout diagram
Giving feedback to someone without sounding prejudiced
How to draw a matrix with arrows in limited space
Is there a RAID 0 Equivalent for RAM?
How can ping know if my host is down
Can I cause damage to electrical appliances by unplugging them when they are turned on?
Stack Interview Code methods made from class Node and Smart Pointers
What are some good ways to treat frozen vegetables such that they behave like fresh vegetables when stir frying them?
Delete multiple columns using awk or sed
Does the Linux kernel need a file system to run?
C++ copy constructor called at return
awk assign to multiple variables at once
How does electrical safety system work on ISS?
Make a Bowl of Alphabet Soup
The IT department bottlenecks progress, how should I handle this?
Are Captain Marvel's powers affected by Thanos breaking the Tesseract and claiming the stone?
Is this toilet slogan correct usage of the English language?
Which was the first story featuring espers?
The Digit Triangles
Autocomplete selenium
How do you disable browser Autocomplete on web form field / input tag?jQuery autocomplete tagging plug-in like StackOverflow's input tags?Removing input background colour for Chrome autocomplete?How to take screenshot with Selenium WebDriverGet HTML Source of WebElement in Selenium WebDriver using PythonNot able to click on the drop down elementUnable to print the Text associated with the li taghow to select the dropdown valueNot able to click on link obtain using findElements methodI am trying to hit on next button in gmail login screen without entering email id , this is basically to test negative scenario
I have the list which has multiple links under each section. Each section has different inks I need to click a particular link under each section. I have written the below code but when it executes it gives me: stale element reference: element is not attached to the page document.
driver.findElement(By.xpath("//*[@id="s2id_CountryId"]/a")).click();
List<WebElement> link2 = driver.findElements(By.xpath("//*[@id="select2-drop"]/ul//li[.]"));
for (int i = 0; i <= link2.size(); i++)
if (link2.get(i).getText().equalsIgnoreCase("ALGERIA"))
link2.get(i).click();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id=\"s2id_GlobalId\"]/a")).click();
List<WebElement> link = driver.findElements(By.xpath("//*[@id="select2-drop"]/ul//li[.]"));
for (int i = 0; i <= link.size(); i++)
if (link.get(i).getText().equalsIgnoreCase("BNZ (Global)"))
link.get(i).click();
java selenium selenium-webdriver autocomplete
New contributor
add a comment |
I have the list which has multiple links under each section. Each section has different inks I need to click a particular link under each section. I have written the below code but when it executes it gives me: stale element reference: element is not attached to the page document.
driver.findElement(By.xpath("//*[@id="s2id_CountryId"]/a")).click();
List<WebElement> link2 = driver.findElements(By.xpath("//*[@id="select2-drop"]/ul//li[.]"));
for (int i = 0; i <= link2.size(); i++)
if (link2.get(i).getText().equalsIgnoreCase("ALGERIA"))
link2.get(i).click();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id=\"s2id_GlobalId\"]/a")).click();
List<WebElement> link = driver.findElements(By.xpath("//*[@id="select2-drop"]/ul//li[.]"));
for (int i = 0; i <= link.size(); i++)
if (link.get(i).getText().equalsIgnoreCase("BNZ (Global)"))
link.get(i).click();
java selenium selenium-webdriver autocomplete
New contributor
What line throws that error? Also, post the relevant HTML in your question.
– JeffC
14 hours ago
add a comment |
I have the list which has multiple links under each section. Each section has different inks I need to click a particular link under each section. I have written the below code but when it executes it gives me: stale element reference: element is not attached to the page document.
driver.findElement(By.xpath("//*[@id="s2id_CountryId"]/a")).click();
List<WebElement> link2 = driver.findElements(By.xpath("//*[@id="select2-drop"]/ul//li[.]"));
for (int i = 0; i <= link2.size(); i++)
if (link2.get(i).getText().equalsIgnoreCase("ALGERIA"))
link2.get(i).click();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id=\"s2id_GlobalId\"]/a")).click();
List<WebElement> link = driver.findElements(By.xpath("//*[@id="select2-drop"]/ul//li[.]"));
for (int i = 0; i <= link.size(); i++)
if (link.get(i).getText().equalsIgnoreCase("BNZ (Global)"))
link.get(i).click();
java selenium selenium-webdriver autocomplete
New contributor
I have the list which has multiple links under each section. Each section has different inks I need to click a particular link under each section. I have written the below code but when it executes it gives me: stale element reference: element is not attached to the page document.
driver.findElement(By.xpath("//*[@id="s2id_CountryId"]/a")).click();
List<WebElement> link2 = driver.findElements(By.xpath("//*[@id="select2-drop"]/ul//li[.]"));
for (int i = 0; i <= link2.size(); i++)
if (link2.get(i).getText().equalsIgnoreCase("ALGERIA"))
link2.get(i).click();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id=\"s2id_GlobalId\"]/a")).click();
List<WebElement> link = driver.findElements(By.xpath("//*[@id="select2-drop"]/ul//li[.]"));
for (int i = 0; i <= link.size(); i++)
if (link.get(i).getText().equalsIgnoreCase("BNZ (Global)"))
link.get(i).click();
java selenium selenium-webdriver autocomplete
java selenium selenium-webdriver autocomplete
New contributor
New contributor
edited 17 hours ago
lelloman
8,79133555
8,79133555
New contributor
asked 19 hours ago
Gnanapriya GGnanapriya G
1
1
New contributor
New contributor
What line throws that error? Also, post the relevant HTML in your question.
– JeffC
14 hours ago
add a comment |
What line throws that error? Also, post the relevant HTML in your question.
– JeffC
14 hours ago
What line throws that error? Also, post the relevant HTML in your question.
– JeffC
14 hours ago
What line throws that error? Also, post the relevant HTML in your question.
– JeffC
14 hours ago
add a comment |
1 Answer
1
active
oldest
votes
you can use:
List<WebElement> listOfLinks = driver.findElements(By.xpath("yourXpath"));
listOfLinks.forEach(link ->
if (link.getText().equalsIgnoreCase("your text"))
link.click();
);
forEach will get each link from your list and it will do with each whatever you have between those brackets. In this case, the if condition.
For the second part you can also use foreach. You can also put waits in for each, so for each link it will wait for a certain time.
If you want to use lambdas, you need java 8.
Edit: after the info you got me, I have managed to write this for you:
public static void main(String[] args) throws InterruptedException
System.setProperty("webdriver.chrome.driver",".//src//browser//chromedriver.exe");
yourMethodName("xpathExample", "xPathListPathExample", "iWantToFindThis","theTextIWantToComplete");
private static void yourMethodName(String xPathOfTheElement,String xPathListPath, String theTextYouWantToFind, String theTextYouWantToComplete) throws InterruptedException
driver.findElement(By.xpath(xPathOfTheElement)).sendKeys(theTextYouWantToComplete);
Thread.sleep(2000);
List<WebElement> listOfLinks = driver.findElements(By.xpath(xPathListPath));
listOfLinks.forEach(link ->
if (link.getText().equalsIgnoreCase(theTextYouWantToFind))
link.click();
);
Hopefully this is clear enough for you.
New contributor
Thanks for ur response... I need to know one more thing... how can I call it on run time.. while in case I have to handle two more autocomplete fields on the same page
– Gnanapriya G
17 hours ago
Here I have been attached by code .. plz overview that,.. and give me suggestion to made changes..
– Gnanapriya G
17 hours ago
@GnanapriyaG I have edited the text above.
– ib23
14 hours ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Gnanapriya G is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55277007%2fautocomplete-selenium%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
you can use:
List<WebElement> listOfLinks = driver.findElements(By.xpath("yourXpath"));
listOfLinks.forEach(link ->
if (link.getText().equalsIgnoreCase("your text"))
link.click();
);
forEach will get each link from your list and it will do with each whatever you have between those brackets. In this case, the if condition.
For the second part you can also use foreach. You can also put waits in for each, so for each link it will wait for a certain time.
If you want to use lambdas, you need java 8.
Edit: after the info you got me, I have managed to write this for you:
public static void main(String[] args) throws InterruptedException
System.setProperty("webdriver.chrome.driver",".//src//browser//chromedriver.exe");
yourMethodName("xpathExample", "xPathListPathExample", "iWantToFindThis","theTextIWantToComplete");
private static void yourMethodName(String xPathOfTheElement,String xPathListPath, String theTextYouWantToFind, String theTextYouWantToComplete) throws InterruptedException
driver.findElement(By.xpath(xPathOfTheElement)).sendKeys(theTextYouWantToComplete);
Thread.sleep(2000);
List<WebElement> listOfLinks = driver.findElements(By.xpath(xPathListPath));
listOfLinks.forEach(link ->
if (link.getText().equalsIgnoreCase(theTextYouWantToFind))
link.click();
);
Hopefully this is clear enough for you.
New contributor
Thanks for ur response... I need to know one more thing... how can I call it on run time.. while in case I have to handle two more autocomplete fields on the same page
– Gnanapriya G
17 hours ago
Here I have been attached by code .. plz overview that,.. and give me suggestion to made changes..
– Gnanapriya G
17 hours ago
@GnanapriyaG I have edited the text above.
– ib23
14 hours ago
add a comment |
you can use:
List<WebElement> listOfLinks = driver.findElements(By.xpath("yourXpath"));
listOfLinks.forEach(link ->
if (link.getText().equalsIgnoreCase("your text"))
link.click();
);
forEach will get each link from your list and it will do with each whatever you have between those brackets. In this case, the if condition.
For the second part you can also use foreach. You can also put waits in for each, so for each link it will wait for a certain time.
If you want to use lambdas, you need java 8.
Edit: after the info you got me, I have managed to write this for you:
public static void main(String[] args) throws InterruptedException
System.setProperty("webdriver.chrome.driver",".//src//browser//chromedriver.exe");
yourMethodName("xpathExample", "xPathListPathExample", "iWantToFindThis","theTextIWantToComplete");
private static void yourMethodName(String xPathOfTheElement,String xPathListPath, String theTextYouWantToFind, String theTextYouWantToComplete) throws InterruptedException
driver.findElement(By.xpath(xPathOfTheElement)).sendKeys(theTextYouWantToComplete);
Thread.sleep(2000);
List<WebElement> listOfLinks = driver.findElements(By.xpath(xPathListPath));
listOfLinks.forEach(link ->
if (link.getText().equalsIgnoreCase(theTextYouWantToFind))
link.click();
);
Hopefully this is clear enough for you.
New contributor
Thanks for ur response... I need to know one more thing... how can I call it on run time.. while in case I have to handle two more autocomplete fields on the same page
– Gnanapriya G
17 hours ago
Here I have been attached by code .. plz overview that,.. and give me suggestion to made changes..
– Gnanapriya G
17 hours ago
@GnanapriyaG I have edited the text above.
– ib23
14 hours ago
add a comment |
you can use:
List<WebElement> listOfLinks = driver.findElements(By.xpath("yourXpath"));
listOfLinks.forEach(link ->
if (link.getText().equalsIgnoreCase("your text"))
link.click();
);
forEach will get each link from your list and it will do with each whatever you have between those brackets. In this case, the if condition.
For the second part you can also use foreach. You can also put waits in for each, so for each link it will wait for a certain time.
If you want to use lambdas, you need java 8.
Edit: after the info you got me, I have managed to write this for you:
public static void main(String[] args) throws InterruptedException
System.setProperty("webdriver.chrome.driver",".//src//browser//chromedriver.exe");
yourMethodName("xpathExample", "xPathListPathExample", "iWantToFindThis","theTextIWantToComplete");
private static void yourMethodName(String xPathOfTheElement,String xPathListPath, String theTextYouWantToFind, String theTextYouWantToComplete) throws InterruptedException
driver.findElement(By.xpath(xPathOfTheElement)).sendKeys(theTextYouWantToComplete);
Thread.sleep(2000);
List<WebElement> listOfLinks = driver.findElements(By.xpath(xPathListPath));
listOfLinks.forEach(link ->
if (link.getText().equalsIgnoreCase(theTextYouWantToFind))
link.click();
);
Hopefully this is clear enough for you.
New contributor
you can use:
List<WebElement> listOfLinks = driver.findElements(By.xpath("yourXpath"));
listOfLinks.forEach(link ->
if (link.getText().equalsIgnoreCase("your text"))
link.click();
);
forEach will get each link from your list and it will do with each whatever you have between those brackets. In this case, the if condition.
For the second part you can also use foreach. You can also put waits in for each, so for each link it will wait for a certain time.
If you want to use lambdas, you need java 8.
Edit: after the info you got me, I have managed to write this for you:
public static void main(String[] args) throws InterruptedException
System.setProperty("webdriver.chrome.driver",".//src//browser//chromedriver.exe");
yourMethodName("xpathExample", "xPathListPathExample", "iWantToFindThis","theTextIWantToComplete");
private static void yourMethodName(String xPathOfTheElement,String xPathListPath, String theTextYouWantToFind, String theTextYouWantToComplete) throws InterruptedException
driver.findElement(By.xpath(xPathOfTheElement)).sendKeys(theTextYouWantToComplete);
Thread.sleep(2000);
List<WebElement> listOfLinks = driver.findElements(By.xpath(xPathListPath));
listOfLinks.forEach(link ->
if (link.getText().equalsIgnoreCase(theTextYouWantToFind))
link.click();
);
Hopefully this is clear enough for you.
New contributor
edited 14 hours ago
New contributor
answered 18 hours ago
ib23ib23
13
13
New contributor
New contributor
Thanks for ur response... I need to know one more thing... how can I call it on run time.. while in case I have to handle two more autocomplete fields on the same page
– Gnanapriya G
17 hours ago
Here I have been attached by code .. plz overview that,.. and give me suggestion to made changes..
– Gnanapriya G
17 hours ago
@GnanapriyaG I have edited the text above.
– ib23
14 hours ago
add a comment |
Thanks for ur response... I need to know one more thing... how can I call it on run time.. while in case I have to handle two more autocomplete fields on the same page
– Gnanapriya G
17 hours ago
Here I have been attached by code .. plz overview that,.. and give me suggestion to made changes..
– Gnanapriya G
17 hours ago
@GnanapriyaG I have edited the text above.
– ib23
14 hours ago
Thanks for ur response... I need to know one more thing... how can I call it on run time.. while in case I have to handle two more autocomplete fields on the same page
– Gnanapriya G
17 hours ago
Thanks for ur response... I need to know one more thing... how can I call it on run time.. while in case I have to handle two more autocomplete fields on the same page
– Gnanapriya G
17 hours ago
Here I have been attached by code .. plz overview that,.. and give me suggestion to made changes..
– Gnanapriya G
17 hours ago
Here I have been attached by code .. plz overview that,.. and give me suggestion to made changes..
– Gnanapriya G
17 hours ago
@GnanapriyaG I have edited the text above.
– ib23
14 hours ago
@GnanapriyaG I have edited the text above.
– ib23
14 hours ago
add a comment |
Gnanapriya G is a new contributor. Be nice, and check out our Code of Conduct.
Gnanapriya G is a new contributor. Be nice, and check out our Code of Conduct.
Gnanapriya G is a new contributor. Be nice, and check out our Code of Conduct.
Gnanapriya G is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55277007%2fautocomplete-selenium%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What line throws that error? Also, post the relevant HTML in your question.
– JeffC
14 hours ago