in robot framewerk text edit using selenium library - python

This is an issue I'm facing while automating my test case via robot framework, I'm trying to click on the Action column of 3rd row in the below table (screenshot below)
The Xpath I'm using is as below
Click element xpath=.//table[id="mylogiusers"]/tbody/tr[3]/td[37]
${table_cell} Get Table Cell xpath=//table[contains(#id,'mylogiusers')]
Click Link ${table_cell}
Note - there are multiple hidden columns in the table, so though the Action column appears to be 10th but in the html table it's number 37, so added td[37] in above xpath.
This is a bootstrap table, please let me know where I'm going wrong, tried multiple options in xpath but none seems to be working here.

Related

Clicking multiple <span> elements with Selenium Python

I'm new to using Selenium, and I am having trouble figuring out how to click through all iterations of a specific element. To clarify, I can't even get it to click through one as it's a dropdown but is defined as an element.
I am trying to scrape fanduel; when clicking on a specific game you are presented with a bunch of main title bets and in order to get the information I need to click the dropdowns to get to that information. There is also another drop down that states, "See More" which is a similar problem, but assuming this gets fixed I'm assuming I will be able to figure that out.
So far, I have tried to use:
find_element_by_class_name()
find_element_by_css_selector()
I have also used them in the sense of elements, and tried to loop through and click on each index of the list, but that did not work.
If there are any ideas, they would be much appreciated.
FYI: I am using beautiful soup to scrape the website for the information, I figured Selenium would be helpful making the information that isn't currently accessible, accessible.
This image shows the dropdowns that I am trying to access, in this case the dropdown 'Win Margin'. The HTML code is shown to the left of it.
This also shows that there are multiple dropdowns, varying in amount based off the game.
You can also try using action chains from selenium
menu = driver.find_element_by_css_selector(".nav")
hidden_submenu = driver.find_element_by_css_selector(".nav # submenu1")
ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform()
Source: here

Python selecting with (java-enabled?) dropdown selection

am new to coding and have been trying to select a dropdown box to select underlying options. Have been able to interact with other drop-down on this page, though this particular one seems different as I've been unable to access/interact with it
I've included a snapshot of the webpage's drop-down box, source codes for the specific drop-down box, and codes that I've already tried and had errors with.
Would appreciate any help/pointers. Am a complete newb to coding (python or HTML!), but know a little about Excel VBA.
website: https://www.firstsentierinvestors.com/sg/en/retail/performance/price-and-performance.html
Tried to paste a picture though it seems I'm too new to do so directly. I'm trying to interact with the "Select Fund" drop-down box on the page. Have tried the following codes:
browser.find_element_by_id('strategy').send_keys(fund_strat) #works fine
browser.find_element_by_xpath('//*[#id="share-class"]').click()
#this line directly above does not work, including variants below:
browser.find_element_by_xpath('THE BELOW XPATHS').click()
//*[#id="price-performance-form"]/div[3]
//*[#id="price-performance-form"]/div[3]/div
//*[#id="price-performance-form"]/div[3]/div/a
//*[#id="price-performance-form"]/div[3]/div/a/span
//*[#id="share-class"]
//*[#id="share-class"]/option[1]
Also tried using CSS selector
browser.find_element_by_css_selector('a.option-selected').click()
browser.find_element_by_css_selector('a.option-selected').send_keys('NAME OF FUNDS ETC')
Image describing problem
If the below line works fine for you then,
browser.find_element_by_xpath('//*[#id="share-class"]').click()
#this line directly above does not work, including variants below:
You need to wait for the element which is visible on the DOM.
i.e.,css = <div class="custom-select custom-select-open">
These days most of the web apps are using AJAX techniques.
So you need to add a wait duration (till the element gets visible on the page or get loaded on the DOM).
So, Try using Selenium Waits(put below code):
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.XX, 'element')))
XX = CSS, XPATH, ID, etc.
Now, If you want to write on the selected text box then just try to send keys on input element.
browser.find_element_by_css_selector('.editable-select input')
for much better selector use parent elements to locate the exact element.
CSS = 'div[class$="custom-select custom-select-open"] .editable-select input'
If you want to select dropdown options and you know the Values. Try using below CSS.
browser.find_element_by_css_selector('select option[value$="Your Value"]')
or
If you don't know the values then please attach whole DOM feed after typing into the text box. I'll try to help you out with the Dropdown selection of item.
Else, there is few more steps are there that you need to workout. Get all elements using inside text.
Note: You can approach the text search of an element using XPATH. Example : xpath = "//*[contains(text(),'your text')]"

Can't scrape data from webpage with popup/frame

I am having trouble finding elements on a customer-facing webpage that I am scraping data from, using Robot Framework + Selenium. My trouble, I think, has to do with the desired data existing in a popup/frame. The data I seek is located on a customer's invoice, which pops up when I press a button ("View Current Invoice"). I've been successful with logging into the site and navigating around, and at one point I was successful pressing the View Current Invoice button to cause the invoice to pop up - but forgot to commit that code and lost it. :-(
In any case, eve if I manually enter the popped up invoice by pressing the button when my script is expecting it to be pressed, I can't seem to scrape the subsequent data. I have tried to identify elements on the invoice using locators (from Right-Click-Inspect capability built into Firefox and Chrome; Katalaon Recorder; Selenium IDE; etc.). I get what looks like a valid locator (almost always Xpath); yet when I run my Robot script, it fails to find the element in question. I have spent a lot of time poring over the page's source code, but since I am not as savvy with HTML/JS/CSS as I should be, I haven't been successful.
Here is a screenshot of the invoice button:
And here is what I see when the button is pressed. I want to scrape all the invoice data, like Amount Due, Invoice Number, Due Date, etc.
Does anyone have any idea what I am missing here? What would you do to get the data on the invoice if you were in my shoes? I know my question probably sounds vague and naiive, but I am at the end of my rope, so to speak. I am willing to share page source code, more screenshots, whatever is required.
EDIT I used Rahul Rai's method to inspect the popup while it was popped up; then searched for "iframe". There were 10 matches; #7, when clicked on, resulted in the invoice popup being highlighted in blue:
I assume this means this is the iframe referencing the popup? If so, I should be able to find information about the "handle" to the iframe in the inspection code, but I don't see anything there that matches the locators I am used to (e.g. name, id, xpath). I even tried "Select Frame 1599252503952", but that just resulted in a
"Element with locator '1599252503952' not found" error.
As per above screen you have shared I can see your Invoice details are inside iframe. So after clicking on View Current Invoice button you can use below code to navigate inside frame and then scrape required information.
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[contains(#src,'invoice_detail_container']")))
#Code to scrape data
ele = driver.find_element_by_xpath('<xpath>')
print(ele.txt)
......
......
#After your work is done in this frame to navigate back to main window
driver.switch_to.default_content()
Note: I have assumed your main frame for invoice is not in side any other iframe ( Based on screen shared). Also before elements start there is no other nested frame. If there is any other nested frame you need to navigate first into that.
I was finally able to scrape data from the Invoice popup after inspecting the HTML source, and seeing this:
<iframe frameborder="0" src="/cmc/invoice_detail_container.pyt?direction=//my.hughesnet.com/cmc/invoice_detail.pyt%3Finvnumber%1234-567890&portletId=863" name="1599391562960" class="cboxIframe" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe>
I was then able to use the Select Frame keyword in Robot Framework, specifying the iframe locator for the popup, using the 'class' strategy. I also had to explicitly select the main body frame first. In the end, the code that allowed me to enter the iframe and scrape was:
Select Frame body
Select Frame class:cboxIframe
Big thank you to Rahul Rai for pushing me closer to the solution; and thanks to the others who answered as well.
You need to switch your site to frame/popup, you can use like below example, may be it will help you.
IList<IWebElement> textfields = new List<IWebElement>();
textfields = driver.FindElements(By.TagName("iframe"));
driver.SwitchTo().Frame(textfields[count); // number of textfields list.
please try to implement as per your scenario, let me know if any question.
You can try to do :
driver.switch_to_active_element()
and then scrape the popup to close it. Then I think it will be okay...

Can't find the button to click with selenium

Trying to click on the button on "https://euw.op.gg/summoner/userName=JengaSneaky". But I can't find the element that trigger it.
The pic shows one of the buttons. I want Selenium to click on it so I can scrape the data that pops up. I've tried to find the element but it says I can't use it with click().
The problem with these kind of buttons is that they are generated each time you load the html ( or the page ) based on the data contained in a database that changes everyday.
That's why they don't come with a unique id or something to distinguish them from others.
The thing you could do here is to find them by the CSS SELECTOR or by XPATH.
But you will always have to check if they changed everyday.
What you could also try to do is locate them if they contain a specific text.

Select a value from a ajax drop down

I am trying to mimic selecting a value from an ajax dropdown value using selenium and python. I am not sure how to approach this.
This is how the text box works - I enter in the value, it searches for it and appears at the bottom of the text box as an ajax drop down. How can I select that using selenium and python?
Here is the highlighted html code for that field

Categories