Clicking a Hyperlink Selenium & Python - python-3.x

Apologizes for the daft question, but really need some assistance
I have recently started to learn python and found some useful tips online:
on how to populate an ID into a field (reference field)
Select a "firms" = true
and also click "search"
Code Snippet below
driver.find_element(By.XPATH,'//*[#id="search-form-search-section-main-input"]').send_keys(cid)
button1 = driver.find_element(By.XPATH,'//*[#id="search-form-search-options-radio-group"]/span[1]/label/span[1]')
button1.click()
button = driver.find_element(By.XPATH,'//*[#id="search-form-form"]/div[2]/div[2]/div[2]/button')
button.click()
print('Search Result Returned')
These values are being passed in the screen shot below;
[
However i am stuck on the next sequential step.
Once all the steps above are completed, it takes me to the following URL: https://register.fca.org.uk/s/search?q=309238&type=Companies
What i would like to do is click on the tile, so that the next page can load (where I can scrape data)
NB : Regardless of where you tick on the tile it takes you you to another page. ( I assume the it’s a hyperlink)
Whilst viewing that page in chrome it appear that this is the section that refers to that "Title"
and the xpath way is //*[#id="firm-result-card-0"]/div/div[1]
However i tried to reference that in my code, and keep getting errors.

Related

Runtime error 7 while using Selenium with VBA for data entry into an online system

I am new in VBA and Selenium. Wrote some lines using Selenium ChromeDriver that can open a online data management system, and log in successfully. I need to manually click on a map, and a table pops up where I need to input some data from a excel sheet using VBA. On that online page, I can access all the components using various methods (e.g., FindElementByName, FindElementByXPath, etc.) **except **the edit boxes and the dropdown elements on the popup table. I even can access the buttons on the bottom of the table. Only when I try to access the elements on the table, it give me the RUN TIME ERROR 7 OUT OF MEMORY. I have attached an image but hid some elements due to the confidential nature of the work. I know it is not a lot of information, but if someone can give me some directions I will highly appreciate it.
Thanks
I am using Selenium Chrome Driver
'Other Subs are here....
Sub Entry()
'I am using these methods to test
myChrome.FindElementByXPath("//div[#class='ui-jqgrid-bdiv']//input[#name='input_ROUTE']").Value = "500"
myChrome.FindElementByName("input_ROUTE").SendKeys "500"
'These throws the Run-time error 7, Out of memory
'However, the same methods works for everything else except the elements on that table
End Sub`
Check the HTML, it is possible that input_ROUTE is inside an iframe element, and the XPath you get is internal inside the iframe.
If this is the case, you need to first move into the iframe and then turn to the internal component. so:
myChrome.SwitchToFrame myChrome.FindElementByXPath("//*[#id=""loginIframe""]") 'Of course you need to change the XPath
myChrome.FindElementByName("input_ROUTE").SendKeys "500"

selenium no such element error element not found for excel

I know this has been asked many times, I apologize for that. but i couldn't solve the problem.
I need to export data from excel to chrome web page. but when I press a button on the web page, the small screen opens and I can't find what I'm looking for there.
to be more specific, this is the page I opened. here I click on the button marked red.
enter image description here
A screen like this opens. I need to add data here.
enter image description here
my selenium code is like this.
Public Function kursiyergiris()
Dim tc As Integer
Dim Findby As New Selenium.By
Dim tcekle As Selenium.WebElement
bot.SwitchToNextWindow
Set tcekle = FindElementById("txtTCKimlikNo") // the part where i got the error
tcekle.SendKeys ("12345678")
note: when I search, I can see the "txtTCIDID" part.
thank you for the help.
1: https://i.stack.imgur.com/SXE4T.png
2: https://i.stack.imgur.com/SjnPb.png
Actually "bot.SwitchToNextWindow" is not for the mini window in the 2nd picture. for another window, the login screen. The screen that opens does not have a name. div has name. With the code "Debug.Print bot.IsElementPresent(Findby.ID("RadWindowWrapper_ctl03"))" I can see the div. but I need to write "txtTCIDID" in it.
The 1st photo below is the main screen. The screen where I want to save the second photo. Could you please review it.
enter image description here
enter image description here
It could be that the code bot.SwitchToNextWindow is not switching to the popup window.
Can you replace that code with bot.SwitchToWindowByTitle "{title of the popup window}" and see if that works?

Unable to automate selection of List-box option using Selenium and Python

I have been trying to use Selenium and automate book cataloging on this software called Koha. As part of the process, I need to necessarily select an 'item type' from a drop down menu (image attached)
Koha drop-down
Now, I have tried multiple ways to go about this but all have failed:
Using find_element methods to click on the drop down and select an
option - The options in the drop down are captured as empty elements for some reason (snippet of page source code attached)
Source code of drop-down
Code used:
itemElem = browser.find_element_by_xpath("//select[contains(#id,'tag_942_subfield_c')]")
opElem = itemElem.find_elements_by_tag_name('option')
print([op.text for op in opElem])
print([op.value for op in opElem])
print([op.id for op in opElem])
Result of print statements:
['','','','','','','']
Execute JavaScript queries to interact with DOM - I am able to click on the drop down but a search for the list box elements returns an error (images of HTML code for page)
For drop-down,
Drop-down options
Code used:
java_script = "document.getElementsByClassName('select2-choice')[2].click();"
browser.execute_script(java_script)
javaScript = "document.getElementsByClassName('select2-result-label')[5].click();"
browser.execute_script(javaScript)
Result of code:
Error occurred while filling in MARC fields.
Message: TypeError: document.getElementsByClassName(...)[5] is undefined
Anything else I could possibly try? Let me know if sharing more of the HTML code might help.

Robot- Selenium : How we can handle a element (text box) whose ID is changing dynamically

I am facing one simple problem-- there is one Add button in the web page, After clicking that a small pop up window (Not in another browser tab , without title) opened having 3 text box. These id/xpath is getting changed whenever will click on Add button. I need to to enter few data and then save.
Could you please help me how we can handle this dynamic xpath/id ---text box in robot selenium framework. Is there any way we can input on text box based on label. Please share any pointer or sample code.
Thank you very much for the help.

Watir : How do we capture the subitems displayed by doing mouseover on a particular item

I am trying to work with mouseover on a particular Item in my application by using the following command
{
ie.text_field(:xpath, "//a[contains(text(),'Deal')]").fire_event('onmouseover')
}
On doing mouseover on a item, two subitems are displayed.
Is there any way to capture the sub items which are part of the Item by doing mouseover with which we can report that our test is pass or fail.
Please suggest.
Additional Information :
If we take example,On the StackOver flow page, If i do mouseover on my name, i get a window where i see activity, privileges, Logout and other stuff. This is really what i was looking for. Is there a way to capture the items displayed on the window on doing mouseover.
I also tried to capture the subitems with the following :
{
text=ie.text_field(:xpath, "//a[contains(text(),'Deal')]").fire_event('onmouseover')
puts(text.inspect)
}
On doing this "text" value is displayed as 'nil'.
My general tactic for such things is a combination of using IRB and the IE Developer tool, or Firebug.
using IRB, type out (or cut and paste) the watir statement to fire the onmouseover command to the proper element on the page.
Then have the developer tool rescan the DOM (there's a little refresh icon you can click) The use the tool to point to an element to point to one of the items in the stuff exposed by the onmouseover. Using the info from that, you can then figure out how to address those elements to get the text from the proper div, etc.
If I do that here to the info that opens up when I float the mouse over my name I can find out that it is a table of class "profile-recent-summary" Furthermore I can then look at the way the table is made up and see for example that the 'today' reputation value is in the second cell on that row.. The row also has the text 'reputation' in it.. so
browser.table(:class, 'profile-recent-summary').row(:text, /reputation/).cell(:index, 2).flash
Should flash the cell I want (index might be 1 if using firewatir or webdriver) I can then replace the .flash with something else like .text if I want to get the text from that cell (which is actually inside a link that sits in the cell)..
without seeing your code, I would 'inspect' the element that you are trying to verify and when_present (text) assert that its true

Resources