CLICK 1 button from same buttons using pycharm selenium - selenium

i have two buttons from which i want to click one button, ID for those both button is same. How can i distinguiush between these two buttons.
Action
Action

This is working for me.
try:
driver.find_element(By.XPATH, "(//*[#id='LnkDetails'])[2]").click()
except:
driver.find_element(By.ID, "LnkDetails").click()

Related

robotframework- unable to click a button on a modal dialogue box

when I open a particular webpage it has a EULA form that appears on top of the home page in the form of a modal in HTML/CSS. I have tried the XPath of the accept button but it says element not found also tried using handle alert.
is there a unique way to handle a dialogue box in robotframework?
image of HTML in inspect view
SeleniumLibrary.Set Focus To Element ${button_on_popup_page}
SeleniumLibrary.Click Element ${button_on_popup_page}
I figured it out, shown in the above code. I first set focus to the button and then used the click element. This seemed to work.

how to submit a form with submit button outside form

i already used all possible scripts and i cannot click this button
element location
Submit
Did u try webelement in selenium Xpath=//tagname[#attribute='value'] ?

selenium, hidden button by overlapped input ( not clickable)

Is there any way on how to click a hidden button by an overlapped input text field, for example if you go to www.google.com and enter a text to search for, selenium can not find the "Search Google" button because it is hidden by the autocomplete of the text field.
Thanks.
You can bypass the validation by using #click! instead of #click. Basically, this triggers the click via JavaScript rather than through standard Selenium commands.
browser = Watir::Browser.new
browser.goto('www.google.com')
browser.text_field(name: 'q').set('watir')
browser.button(name: 'btnK').click!
If you are only using Selenium, you can do:
btn = driver.find_element(name: 'btnK')
driver.execute_script('arguments[0].click();', btn)
As discussed in the comments, you could also close the suggestions box before trying to click the button. You can do this by moving focus to any other element - eg the first link on the page. Depending on what you're testing, this may or may not have value.
browser.text_field(name: 'q').set('watir')
browser.link.focus # move focus to any other element so suggestions close
browser.button(name: 'btnK').click

How to click on "Stay on this page" button on confirm Navigation pop-up when i moved one form to other form without save entered value in selenium

In my application,when i enter some values in available fields and without click on save button if clicked on other available form tab than comes a confirm Navigation pop-up which have buttons "Stay on this page" or "Leave this page".
I have to click on "Stay on this page" button and than click on submit button.
I tried with Alert class alert.dismiss(); which closed pop-up but i want to click on "stay on this page" button.
Can anyone please help me to do this thing in selenium .
When I move from one page to other without clicking on save button i got this confirm Navigation pop-up:
I Hope this will work, First you need to switch on that alert
Alert alert = driver.switchTo().alert();
and then change focus to Stay on this page tab
alert.sendKeys(Keys.chord(Keys.TAB));; //By pressing TAB key in this way
and then click the button
alert.dismiss();
This approach is working at my end

Selenium - How to click OK button in a pop up using text containing in that button

The code below is shown in firebug for the OK button in the popup of my application
<button id="ext-gen219" class="x-btn-text" type="button">
OK
</button>
Here the button id is randomly generated and also the position of ok button is not identifiable. Is there a way to click on the button by its text? Like the button contains a text called OK.
For Selenium IDE or Selenium RC, xpath=//button[contains(., 'OK')] ought to be a good locator.
I am going on the premise that the text of the popup boxes are not identical so I would recommend something like this:
List<IWebElement> dialogBox = driver.FindElements(By.Class("dialogBoxClass");
int buttonIndex = dialogBox.FindIndex(i => i.FindElement(By.Class("DisplayedTextElementClass").Text.Contains("some unique text here"));
dialogBox[buttonIndex].FindElement(By.ClassName("x-btn-text")).Click();
This captures the parent element of all the dialog boxes and then parses each object to find the index of the box you want and then clicks on the 'Ok' button in the correct object.
In case of a submit button this locator css=input:submit[value="OK"] should work. In case of a button element take css=button:contains("OK").