GeckoDriver is not entering value for Firstname field within Firefox browser - selenium

Firefox driver is not entering a value for Firstname field.
I'm trying the following:
driver.findElement(By.xpath(//*[#id=\JNHGYHG\"]")).sendsKeys("Hello");
Can someone help me with this?

Try this and see any difference.
driver.findElement(By.xpath("//*[#id='JNHGYHG']")).sendKeys("Hello");

As mentioned in your code trial there is an error within the Locator Strategy you have used.
Solution
You can use either of the following solutions:
Using id attribute:
driver.findElement(By.id("JNHGYHG")).sendKeys("Hello");
Using cssSelector:
driver.findElement(By.cssSelector("#JNHGYHG")).sendKeys("Hello");
Using xpath (option A):
driver.findElement(By.xpath("//*[#id='JNHGYHG']")).sendKeys("Hello");
Using xpath (option B):
driver.findElement(By.xpath("//*[#id=\"JNHGYHG\"]")).sendKeys("Hello");

Related

locating xpath with starts with and ends with

Following xpath I have copied from the browser(inspect)
# // *[ # id = "customize-coverage--customize-your-quote--propertyDamage-1--info-title"]
I am trying to read the element but its just not able to locate it with the follwoing xpath
Is there anyway I can locate the above element by selenium? Please help. I am not sure why the belwo is not working to locate the web element by driver
return self.page_element(By.XPATH,
'//*[starts-with(#id,"customize-coverage--customize-your-quote--propertyDamage-") and ends-with(#id,"-info-title")]/span').text
I tried to use contains and regex also. Nothing seems to work.
Note: I am using python
ends-with() requires XPath 2.0, and although that's now nearly 14 years old, Selenium doesn't implement it yet. You have to use a combination of substring() and string-length().

Is there a way to click an element using Partial text or complete Text using Appium

I am trying to click an element with text "No, Thanks" using below code, I tried various options so far such as
driver.findElementByXPath("//*[contains(text(),'THANKS')]").click();
driver.findElement(By.name("No,THANKS")).click();
driver.findElementByName("No,THANKS").click();
There is no other element with same text. I am using Appium Driver and Samsung device.
If it is TextView, you can consider the following
driver.find_element_by_xpath("//android.widget.TextView[#text='No, Thanks']")
Seems you were close. The text No, Thanks contains a , character in between which you need to avoid. So effectively you can use either of the following xpath based Locator Strategies:
xpath 1:
driver.findElementByXPath("//*[starts-with(., 'No') and contains(., 'Thanks')]").click();
xpath 2:
driver.findElementByXPath("//*[contains(., 'No') and contains(., 'Thanks')]").click();
Please try this:
driver.findElement(By.xpath("//android.widget.TextView[contains(#text,'No, Thanks')")).click();

How to find webelement using style property

Below is the HTML code of an element and I want to locate this element by classs and style property using selenium webDriver in java
<div class="qooxdoo-table-cell" style="left:252px;width:117px;height:24px;"/>
suggest a way which can be help full in selenium
I want to locate the element using java code
i.e. Driver.findelement(by. ....
As long as the element isn't unique you must grab both attributes:
This is the general form, replacing the empty strings for your required class and style:
driver.findElement("By.xpath(//div[#class='' and style='']");
So:
driver.findElement(By.xpath("//div[#class='qooxdoo-table-cell' and style='left:252px;width:117px;height:24px;']");
Best of luck!
If you need to match <div> with exact style attribute, you can try something like
driver.findElement(By.xpath("//div[#class='qooxdoo-table-cell'][#style='left:252px;width:117px;height:24px;']"))
Another way is to use cssSelector as follows:
driver.findElement(By.cssSelector("div[style='left:252px;width:117px;height:24px;']"));
If you are using a older version of selenium you can as well use the older version of cssSelector.
driver.find_elements_by_css_selector("div[style='left:252px;width:117px;height:24px;']")
Note: this function still works in current version of Selenium (with DeprecationWarning )

Selenium Webdriver: cssselector

I am trying to do SignIn for this. In it click on 'SignIn' which I have done it successfully. Now when trying to type in Username/Password using Xpath it shows exception which says
Exception in thread "main"
org.openqa.selenium.ElementNotVisibleException: element not visible
code is :-
driver.findElement(By.xpath(".//*[#id='load_form']/fieldset[1]/input")).sendKeys("test123");
driver.findElement(By.xpath(".//*[#id='load_form']/fieldset[2]/input")).sendKeys("test123");
I know this Xpath is same as used in SignUp form, so what are the other ways to locate these two fields? How we can use it by using cssselector?
Thanks for the help in advance.
Go One Level up on finding the relative xpath with
//div[#id='login']/form[#id='load_form']//input[#name='username']
//div[#id='login']/form[#id='load_form']//input[#name='password']
Try this
//For Username
driver.findElement(By.xpath("(//input[#name='username'])[2]")).sendKeys("username test");
//or
driver.findElement(By.cssSelector("#login > #load_form > fieldset > input[name='usernam']")).click();
//For password
driver.findElement(By.xpath("(//input[#name='password'])[2]")).sendKeys("password test");
//or
driver.findElement(By.cssSelector("#login > #load_form > fieldset > input[name='password']")).click();
the above codes are working for me.
There are basically two elements found by provided xpath, and it works with first found element which is invisible as your exception saying, you should try using cssSelector as below :-
driver.findElement(By.cssSelector("div#login input[name = 'username']")).sendKeys("test123");
driver.findElement(By.cssSelector("div#login input[name = 'password']")).sendKeys("test123");
Note:- For learning about cssSelector follow this url and for xPath follow this url
I'm suggesting you before selenium execution with the locator you need to sure that using locator is correct and returns single or multiple element at your browser console by pressing f12. for verify xPath you should use $x("your xpath expression") and for cssSelector you should use document.querySelector("your css selector expression")..
Hope it will help you..:)

Not able to identify a lenghty linktext in selenium webdriver

I want to identify an element by linktext, I am facing strange issue
If the linktext value is short i.e addFirst, addLast will be able to locate the element by using
driver.findelement(By.linktext("addLast, addFirst")).click
IF the linktext is addmanualreferraltocheckthelenghtF, addmanualreferraltocheckthelenghtF lengthy as above not able to identify the element
Please help me to find the solution
Why don't you try partial link text.
driver.findelement(By.partialLinkText("addLast, addFirst")).click
try out contains method. use the XPATH value and in XPATH use contains for link text.
EG:
.//*[contains(#Linktext, "addmanualreferraltocheckthelenghtF")]
driver.findelement(By.xpath("//*[contains(#Linktext, "addmanualreferraltocheckthelenghtF")]").click
Alternatively you can also use starts with XPATH value.
.//*[starts-with(#linktext,'addmanual')]
driver.findelement(By.xpath("
//*[starts-with(#linktext,'addmanual')]").click
Hope it helps you.