Development

I am trying to launch my application in IE browser in selenium using TestNG framework. But, after the IE browser is launched, the Eclipse console shows an error that “Only Local Connection are allowed”.

My IE browser is set to zoom 100%, the Protected mode is set as expected. I am executing the script on Windows 10 64 Bit. Selenium version is 3.0.1 and IEDriverServer.exe is 64-bit as well.

How to identify this button in C#:

<button class=”reward_link_redeem_button_style” onclick=”RedeemRPProduct(‘free_points_1’)”>REDEEM</button>
<button class=”reward_link_redeem_button_style ” onclick=”RedeemRPProduct(‘free_points_50’)”>REDEEM</button>

But there are like 4 buttons called equal, and to differentiate them you need the (‘free_points_1’) as well as (‘free_points_10’), etc.

As per the below code, I navigate to a specified URL and select the values in the from and to field.
The xpaths mentioned in the 3rd and 4th line, each returns 2 instances.
In the third line, findElement selected the first instance.
But in the fourth line, the findElement method selected the second instance.
As per my understanding, findElement method will always select the first instance.

So, is there any specific xpath logic which caused it to select the second instance or what is the difference between 4th and 5th line in this context ?

Below is the code:

driver.get(“https://www.spicejet.com”);
driver.findElement(By.xpath(“//input[@id=’ctl00_mainContent_ddl_originStation1_CTXT’]”)).click();
driver.findElement(By.xpath(“//a[@value=’GOI’]”)).click();
driver.findElement(By.xpath(“//a[@value=’DEL’]”)).click();
driver.findElement(By.xpath(“(//a[@value=’DEL’])[2]”)).click();

Appreciate your help on this.

I just want it to past the first page by selecting “1” from the dropdown menu and clicking on “Weiter” but I couldn’t even get it to find the menu so I tried to make it send the data directly to the server and jump to the next page where the appointments should be then showned. But I am getting the message “Access denied to this page (403)” from Microsoft Edge… What should I do? I have actually no idea of what I am doing… I’ve been using ChatGPT to help me with the code. Thanks!
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.edge.service import Service
from selenium.webdriver.edge.options import Options
import time
Path to the Microsoft Edge WebDriver
webdriver_path = “C:UsersthejaDesktopBotmsedgedriver.exe”
URL of the website
url = “https://stadt.muenchen.de/terminvereinbarung_/terminvereinbarung_abh.html?cts=1000113”
Set up the Edge WebDriver with a custom User-Agent
options = Options()
options.headless = False # Run in normal mode to see the browser
options.add_argument(“user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36”)
service = Service(webdriver_path)
driver = webdriver.Edge(service=service, options=options)
try:
# Open the website
driver.get(url)
# Wait for the page to load completely
wait = WebDriverWait(driver, 20) # Increased wait time
wait.until(EC.presence_of_element_located((By.TAG_NAME, “body”)))

# Execute JavaScript to submit the form
script = “””
var form = document.createElement(‘form’);
form.method = ‘POST’;
form.action = ‘https://stadt.muenchen.de/terminvereinbarung_/terminvereinbarung_abh.html?cts=1000113’;

var token = document.createElement(‘input’);
token.type = ‘hidden’;
token.name = ‘FRM_CASETYPES_token’;
token.value = ‘397017935ccff9a3e347532ef2898855’;
form.appendChild(token);

var step = document.createElement(‘input’);
step.type = ‘hidden’;
step.name = ‘step’;
step.value = ‘WEB_APPOINT_SEARCH_BY_CASETYPES’;
form.appendChild(step);

var caseType = document.createElement(‘input’);
caseType.type = ‘hidden’;
caseType.name = ‘CASETYPES[Notfalltermin UA 35]’;
caseType.value = ‘1’;
form.appendChild(caseType);

document.body.appendChild(form);
form.submit();
“””
driver.execute_script(script)

# Wait for the next page to load
wait.until(EC.presence_of_element_located((By.TAG_NAME, “body”)))

# Keep the browser open for further actions
print(“Browser will remain open. Press Ctrl+C to exit.”)
while True:
time.sleep(1)

except Exception as e:
print(f”An error occurred: {e}”)
driver.save_screenshot(“error_screenshot.png”) # Save a screenshot of the error
Do not close the browser, keep it open for further actions