Find web element xpath for button - selenium

not able to locate the web element "Next" button, where the Absolute xpath for the button is
//*[#id="RULE_KEY"]/div/div/div/div/div/div/div/div/div/div/div/div/div/div/div/div/span/button/div/div/div/div
Provide the relative xpath, But i tried with the below one which is not working - xpath =
"//span[contains(text(),'Next >>')]"

Try following xpath
//*[#id="RULE_KEY"]//button//span[contains(text(),'Next >>')]

Related

Locate a button which has a span with specific text in Selenium python

I have following html snippet:
<button><span>Next</span></button>
I want to locate this button and I am using the following:
driver.find_element_by_xpath("//button[#span[.='Next']]")
Also used:
driver.find_element_by_xpath("//button//span[.='Next']")
but this locates the span instead of the button :(
But no luck with this. Does anyone know what is the correct way for the same?
Try this XPATH to locate button based on child span text content
"//button[span='Next']"
Try this xpath:
driver.find_element_by_xpath("//span[text()='Next']//parent::button")

How do I click this XPath button with Selenium for Python?

The XPath is:
//*[#id="pricing_table_1"]/div[1]/div/div[1]/div[3]
But it doesn't work on click using:
browser.find_element_by_xpath('//*[#id="pricing_table_1"]/div[1]/div/div[1]/div[3]').click()
What am I doing wrong? Thanks.
The element you are trying to find is inside another frame, so first you need to switch to that frame and then search the element.
Try this:
browser.switch_to.frame(browser.find_element_by_tag_name("iframe"))
browser.find_element_by_xpath('//*[#id="pricing_table_1"]/div[1]/div/div[1]/div[3]').click()

How can i click on the login button in selenium webdriver of website Http://Phptravels.Com/Demo/

I want to click on login button. Which attribute should I use to click on login button? I am new to selenium web driver. I am unable to find its link text, id, class name, name. I am not able to find its XPath or CSS selector. please advice me with the code. Image is here
You can use either Xpath which is
.//*[#id='main-menu']/ul/li[8]/a
or CSS Selector which is
.login
To click on element with text as LOGIN within the url https://phptravels.com/404/ you can use either of the Locator Strategies:
CssSelector:
"a.login[href='http://phptravels.org']>span"
XPath:
"//a[#class='login' and #href='http://phptravels.org']/span[contains(.,'LOGIN')]"
//or
"//a[#class='login' and #href='http://phptravels.org']/span[contains(.,'Login')]"
You have multiple options, just avoid using xpath since its an overkill
li.user-login>a.login>span
or
a.login>span
or xpath
.//a[#class='login']/span[text()='Login']

WebElement is identified through xpath in the developer console but the element wont be identified through selenium findElement method

The html element Im trying to locate is the "Shared" link.
I wrote a dynamic xpath to locate the element and it shows as the element was identified in the developer console.
But when i use the xpath that i wrote in the developer console to locate the element using selenium, it does not locate the element.
The method i used to check if it locates the element is shown below.
I could not figure out why this issue occurs, Is it because of a issue in the xpath that i have written or because of another issue?
Code you can try out is :
new WebDriverWait(driver,10).until(ExpectedConditions.elementToBeClickable(By.xpath(" your Xpath ")));
driver.findElement(By.xpath("your Xpath")).click();
The Xpath you have written would work if only one title is present on current page.
driver.find_elements doesn't have attribute to click() so use driver.findElement instead of Elements

Unable to locate dynamic input element with Selenium

I have a textfield in my application , it gets enabled when i click on it. I am able to do click using CSS but i am unable to enter text when it got highlighted.
I tried using xpath to idenfify the dynamicly but webdriver is throwing an error
"Unable to locate element:
{"method":"xpath","selector":"//input[#class='x-form-field
x-form-text']"}![enter image description here][1]
showed the difference before n after clicking on the field in thescreen shot.
Please help in how to dynamically identify and enter the text in that field
try the following:
String cssSelector = "[class='x-form-field x-form-text']"
//but verify found css selector in firepath, firebug addon in ffox to make sure selenium //locate web element for input properly.
driver.findElement(By.cssSelector(cssSelector)).clear();
driver.findElement(By.cssSelector(cssSelector)).sendKeys("blablabla");
Hope this works for you
Try this code:
String cssSelector = ".x-form-field x-form-text"
driver.findElement(By.cssSelector(cssSelector)).clear();
driver.findElement(By.cssSelector(cssSelector)).sendKeys("blablabla");
Let me know is the above scripting is working or not.