other webelement is also treated as List<WebElement> [closed] - selenium

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
After accessing the webelements of List. Other webelement is also treated as List webelement.
List<WebElement> BrandTerms =driver.findElements(BrandTerm);
js = (JavascriptExecutor) driver;
for(int i=0;i<=1;i++)
{
js.executeScript("arguments[0].value='"+Bandtermsvalue+i + "'", BrandTerms.get(i));
}
js=null;
driver.findElements(By.id("btnAddBrandedTerms")).click();
Why is this webelement is treated as list element with message "click() is undefined for the type List"

alternatively You may extract and click on the first found
List<WebElement> BrandTerms =driver.findElements(BrandTerm);
js = (JavascriptExecutor) driver;
for(int i=0;i<=1;i++)
{
js.executeScript("arguments[0].value='"+Bandtermsvalue+i + "'", BrandTerms.get(i));
}
js=null;
driver.findElements(By.id("btnAddBrandedTerms")).get(0).click();
OR
driver.findElement(By.id("btnAddBrandedTerms")).click();
Please see webdriver API specs
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/remote/server/handler/FindElement.html
and
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/remote/server/handler/FindElements.html
Also highly recommending to double check selenium top tips and tricks and try that out in your project.
Hope this helps.

findElements returns a list of all the elements which match given xpath. Whereas, findElement returns first matching element using the xpath. But, be careful as if there is no element matching the given xpath, you may face exception.
To solve the issue you are facing, instead of below line:
driver.findElements(By.id("btnAddBrandedTerms")).click();
Please use this line of code:
driver.findElement(By.id("btnAddBrandedTerms")).click();
Hope it helps.

Related

Xpath element not found [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
I can't find my link using this Xpath //a[contains(text(),'My stuff')]
Though I can find it through DOM :
HTML :
<li _ngcontent-c8="">
<a _ngcontent-c8="" href="my-stuff">
{" "}
My Stuff{" "}
</a>
</li>;
When executed :
try:
my_stuff = WebDriverWait(driver, 8).until(
EC.presence_of_element_located((By.XPATH, "//a[contains(text(),'My stuff')]"))
)
my_stuff.click()
except:
print("not found")
returns not found
There was a modal messing with my selection that needed to be dissmissed.
i will try to analyse the problem and give you most answer
. first : if you have Xpath Helper "google chrome extension" try to put your Xpath there
=> if you find it then the problem in your code . we will try to change it
=> if you can't find it with Xpath helper ,than there is multiple choice:
first try to find if there is a "table" or new "form" above your Xpath , that you can't get it with absolute path
. you must get inside the "table" or "form", then find the path inside it
, tell me if that didn't work

What is the xpath of gmail password field in firefox browser [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am trying to automate gmail in firefox browser using selenium webdriver and firebug.
Selenium is not identify the xpath of the password fileld.
what is the xpath of the password field.
Try below mentioned xpath:
//*[#name="password"]
I suggest you to verify the xpath on Console of Chrome Browser.
If your application supports Chrome with below mentioned syntax
$x("//*[#name='password']")
While you try to log into your Gmail Account, on filling up the EmailID/Phone field with text and simultaneously click on the Next button, the text field for Password takes a delta amount of time to be clickable/interactable within the Viewport. Hence apart from just locating the xpath for Password field you have to induce some Explicit Wait i.e. WebDriverWait as follows:
WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement password = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[#name='password']")));
password.sendKeys("your_password");
Try the below xpath :
By.xpath(.//*[#id='password']/div[1]/div/div[1]/input)
Use this :
//input[#type='password']
else you can locate like
driver.findElement(By.name("password"));
Use this xpath:
//INPUT[#type='password']
Try this one. firebug is outdated I would suggest you use other softwares for more complex xpaths.
use this xpaths
//input[#class='whsOnd zHQkBf'][#name='password']
//input[#type='password']
//*[#type='password']
//input[contains(#aria-label,'Enter your password')][#name='password']
//input[contains(#aria-label,'Enter your password')][#autocomplete='current-password']
Instead of using xpath you should use name as it have priority over xpath like this:
System.setProperty("webdriver.chrome.driver", "E:\\software and tools\\chromedriver_win32\\chromedriver.exe");
WebDriver chrome_driver = new ChromeDriver();
chrome_driver.findElement(By.name("password")).sendKeys("xxxxxxxxxx");
or you can use any xpath
chrome_driver.findElement(By.xpath("xpath you want")).sendKeys("xxxxxxxxxx");
Use any of below XPath
//input[#type='password']
OR
//input[#name='password']
OR
//input[contains(#aria-label,'Enter your password')]
OR
//input[contains(#autocomplete,'current-password')]
The complete code will like below :-
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.findElement(By.name("identifier")).sendKeys("xxx#gmail.com");
driver.findElement(By.xpath("//span[contains(.,'Next')]")).click();
driver.findElement(By.name("password")).sendKeys("123456");
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//span[contains(.,'Next')]")));
element.click();

Not able to click or page not responding to click in phantomjs-selenium in java

I am doing project on different crawlers and trying to mimic user actions. As part of it, I am crawling this url. Here there is a zip code box and I am trying to click on it and extract text from the drop down which will appear after that. I wrote the below code but not sure why it is not working at all. Can anyone please help? I did exhaustive search to find root cause but got nothing. Any suggestions would be much much appreciated.
driver.getUrl(aboveUrl);
WebElement inputBox = driver.findElement(By.id("pincodeInputId"));
inputBox.click();
System.out.println(driver.findElement(By.className("_3mWImx")).getText());
-- This gives null;
Awaiting help !
The reason is the node that you picked is the parent node of the element that has the text
You should use
System.out.println(driver.findElement(By.css("_3mWImx span")).getText());
And that would work. Also note that there are multiple element with the class _3mWImx, so this will only give you the first one. If you are interested in all of them, then you should be using driver.findElements and looping through the result
Actually there are more than one values in the drop down if you want to print all you have to used findElements(). Use this code it will give you desired result :
WebDriver driver=new FirefoxDriver( );
driver.manage().window().maximize();
driver.get("https://www.flipkart.com/moto-e4-plus-fine-gold-32-gb/p/itmevqynuz4fwxca");
WebElement inputBox = driver.findElement(By.id("pincodeInputId"));
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
inputBox.click();
List<WebElement> elements=driver.findElements(By.className("_3mWImx"));
for(WebElement ele:elements)
{
System.out.println(ele.getText()); //It will print innertext of each element
}
Output :
From Saved Addresses
Loginto see your saved addresses

Selenium xpath each element 5 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I use selenium and xpath selector. I know how to get a certain element. But how to use xpath to get each element 5?
You can always solve it in your language of choice.
Python
For example, in Python, the extended slicing allows to do it rather simply:
driver.find_elements_by_xpath("//table/tr")[0::5]
You can also use the position() function and the mod operator:
//table/tr[position() mod 5 = 0]
driver.find_elements_by_xpath("//table/tr[position() mod 5 = 0]")
Java
List<WebElement> elements=driver.findElements(By.xpath("//tbody/tr[position() mod 5 = 0]"));
System.out.println(elements.size());
for (WebElement element : elements) {
System.out.println(element.getText());
}

Robot Framework: How to clear the text in Textfield [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I want to know that how to remove the text from Textbox. I have did much search from Google but nothing found currently. Please tell me any Keyword which can help me for remove/clean text in field.
You can use this also for clear test field..
driver.findElement(By.id("textfieldid")).sendKeys("");//empty string
or
Input Text (your web element locator ) ${empty}
You don't need a Robot to do it.. Just use Selenium.
driver.findElement(By.id("username")).clear();
http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html#clear()
You don't need it. Check here
def input_text(self, locator, text):
"""Types the given `text` into text field identified by `locator`.
See `introduction` for details about locating elements. """
self._info("Typing text '%s' into text field '%s'" % (text, locator))
self._input_text_into_text_field(locator, text)
The Input Text keyword is calling the
_input_text_into_text_field
which is anyway sending the clear command:
def _input_text_into_text_field(self, locator, text):
element = self._element_find(locator, True, True)
element.clear()
element.send_keys(text)