Find HTML span element - html

HTML screenshotI am trying to build a test case to select an option from the drop down menu but unable to find the element.
I am new to selenium webdriver module I can find elements using xpath and id but unable to find an element from a drop down menu.
I am able to log into the webpage and click "Queues". Now I want to select "All Items" from the queue but gettig errow
All Items

If you are not able to find it by selenium and exception is throwing like element not found that probably there is a frame present and your element is inside it. you need to switch to the frame first.
You can refer my or other answer in below link:
How to select frame if there are multiple frames on a webpage and get content of that frame?
If you are not able to find in HTML then use below code
System.out.println(driver.getPageSource());
It just going to print your HTML, now copy it in notepad++ and search your dropdown Text. now create Xpath

Related

How to click on this web element using selenium webdriver?

HTML
How would you click on this particular item in selenium each time by having just the date you want as a variable? I have shown the item in the attached image of the HTML. It is a panel calendar, however, I can't find the item using by.ID, class, etc. I can Click on it by using XPath however how do I make it specific to the data? I would like to click on it based on the.
data-moment="2022-10-30"
currently I just have this:
### Gets Edge driver and doesnt need extension update
driver = webdriver.Edge(service=EdgeService(EdgeChromiumDriverManager().install()))
driver.get(
'https://teewire.net/granada/'
)
driver.maximize_window()
pause(5)
driver.find_element(By.XPATH,"//*[#id='gz-time-slot-calendar']/ul/li[4]/a").click()
pause(10)
Change your XPath to this:
data_moment = "2022-10-30"
driver.find_element(By.XPATH,f"//*[#id='gz-time-slot-calendar']//a[#data-moment='{data_moment}']").click()

Selenium state of button to be clicked

I have a site which is populated from a database. I want to access the pages in Selenium. The number pages associated with a particular topic is variable.
Using Selenium I am clicking through successive pages using a line like
driver.find_element_by_xpath("""//*[#id="mainContent"]/
div[2]/div/div[2]/div[1]/
div[3]/div[2]""").click()
This works successfully.
However I would like to detect when the element I am clicking (a next button) is "greyed" out rather than having to predict how many pages are available.
Currently I am using a block of code inside a for loop with a counter for the number of available pages.
EDIT: The page element has the word Inactive added when it is "greyed out" as in
<div class="paginationBtn paginationNextContainer inactive"><div class="icn chevron-left"></div><div class="visuallyHidden">Previous</div></div>
If your button is changing its color on click, it's associated with CSS attribute.
I advise to look at this answer to learn the subject. For your case, I advise you to develop a method to get the button color value before and after, as your script should operate accordingly.

Is it true that DIV elements cannot be clicked with selenium Web Driver?

Is it true that DIV elements cannot be clicked with selenium Web Driver?
For Instance, I'm unable to click on delete button in Gmail
Am trying to locate the elemnt using XPATH = //div[#aria-label='Delete']
here, class names and id's are dynamic which changes for every session. Imean, for every Login and Logout. I want my script to be Robust to run at any time.
You can by class name or ID, e.g. with class:
driver.findElement(By.className("class")).click();
Or by element name:
driver.findElement(By.ByTagName("div")).click();
Or find the parent or child a tag.
Have you tried using a different attribute ?
For e.g. you can use
//div[#data-tooltip='Delete']
or
//div[#data-tooltip='Delete']/div/div
It may derive because of gmail has async structure. You may wait to finish request after page load and after select action. If you can share code flow we can examine together.

How do I find X-Path for elements within a frameset?

I'm trying to write a test case for Selenium and I'm having a little trouble finding elements. I believe its because my site uses a HTML frame set.
If I open up Firebug, and try to simply select all links:
//a
... I get no results (although the 'menu' frame contains about 15+ links).
If I right-click in the menu frame and choose to "Show Only This Frame", and then select all links in Firebug, I get all 15+ links returned.
This leads me to believe X-Path cannot iterate through elements within a specific frame. Is that true?
When the site is showing all frames, I can select the specific frame:
//frame[#name='menu']
...but trying to drill down to the links starting with that X-Path does not work:
//frame[#name='menu']//a
//frame[#name='menu']###//a <-- Special '###' syntax I read about somewhere to try.
Any help trying to solve this with X-Paths is appreciated. If a CSS selector will work, I could use some pointers there as well. Thanks!
jg
How about you first select the relevant iframe, and then work with the xpaths within that frame.
Sample code in Ruby
iframename = #driver.execute_script("return document.getElementById('IDName').getElementsByTagName('iframe')[0].getAttribute('Attributename')")
#driver.switch_to.frame iframename
# then work with the xpaths
#driver.find_element(:xpath, "//section[#id='SomeId']/div").click
this should help, unless I got the question wrong.

Binding to HTML elements in GWT

I'm trying to figure out how to bind a javascript event to a select element in GWT, however the select element isn't being built in GWT, but comes from HTML that I'm scraping from another site (a report site from a different department). First, a bit more detail:
I'm using GWT and on load, I make an ajax call to get some HTML which includes, among other things, a report that I want to put on my page. I'm able to get the HTML and parse out the div that I'm interested in. That's easy to display on my page.
Here's where I get stuck: On the portion of the page I'm using, there's a select element which I can easily locate (it has an id), but would like to capture event if my user changes that value (I want to capture changes to the select box so I can make another ajax call to replace the report, binding to the select on that page, and starting the whole process again).
So, I'm not sure how, once I get the HTML from a remote site, how to bind an event handler to an input on that fragment, and then insert the fragment into my target div. Any advice or pointers would be greatly appreciated!
How about this:
Element domSelect = DOM.getElementById("selectId");
ListBox listBox = ListBox.wrap(domSelect);
listBox.addChangeHandler(new ChangeHandler() {
void onChange(ChangeEvent event) {
// Some stuff, like checking the selected element
// via listBox.getSelectedIndex(), etc.
}
});
You should get the general idea - wrap the <select> element in a ListBox. From there, it's just a matter of adding a ChangeHandler via the addChangeHandler method.