Xpath doesn't work with string, which have quotes. Chrome
I have the text:
var1 = 'ТСЖ "ВОЛГОГРАДСКИЙ ПР-Т 50-1, 52-1, 52-2, 56-1, 56-2, 58-1, 58-3, 60-2, 64-1, 64-2, 66-2, ВОЛЖСКИЙ 21"'
And I have xpath:
driver.find_element_by_xpath("//a[text()='"+var1+"']/ancestor::div[contains(@class,'chakra-stack') and contains(@class,'css-1oap1wr')]/following-sibling::div/descendant::button[text()='Отклонить']").click()
- It does'nt work
//a[text()='ТСЖ "ВОЛГОГРАДСКИЙ ПР-Т 50-1, 52-1, 52-2, 56-1, 56-2, 58-1, 58-3, 60-2, 64-1, 64-2, 66-2, ВОЛЖСКИЙ 21"']/ancestor::div[contains(@class,'chakra-stack') and contains(@class,'css-1oap1wr')]/following-sibling::div/descendant::button[text()='Отклонить']
- But this work!
Python writes me :selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//a[text()='ТСЖ "ВОЛГОГРАДСКИЙ ПР-Т 50-1, 52-1, 52-2, 56-1, 56-2, 58-1, 58-3, 60-2, 64-1, 64-2, 66-2, ВОЛЖСКИЙ 21"']/ancestor::div[contains(@class,'chakra-stack') and contains(@class,'css-1oap1wr')]/following-sibling::div/descendant::button[text()='Отклонить']"}
But if I Cut xpath from error messeage and put it like xpath in console of Chrome - element would finded.
Element absoulutle visible and already loaded. Sory for my English.
1 answer
-
answered 2021-01-19 20:06
DMart
You need to escape the quotes. Try either this:
var1 = 'ТСЖ "ВОЛГОГРАДСКИЙ ПР-Т 50-1, 52-1, 52-2, 56-1, 56-2, 58-1, 58-3, 60-2, 64-1, 64-2, 66-2, ВОЛЖСКИЙ 21"' driver.find_element_by_xpath('//a[text()=\''+var1+'\']/ancestor::div[contains(@class,\'chakra-stack\') and contains(@class,\'css-1oap1wr\')]/following-sibling::div/descendant::button[text()=\'Отклонить\']').click()
or this
var1 = 'ТСЖ "ВОЛГОГРАДСКИЙ ПР-Т 50-1, 52-1, 52-2, 56-1, 56-2, 58-1, 58-3, 60-2, 64-1, 64-2, 66-2, ВОЛЖСКИЙ 21"' #replace the double quotes with \" var1 = var1.replace('"', '\\"') driver.find_element_by_xpath("//a[text()='"+var1+"']/ancestor::div[contains(@class,'chakra-stack') and contains(@class,'css-1oap1wr')]/following-sibling::div/descendant::button[text()='Отклонить']").click()
See also questions close to this topic
-
AzureML Machine Learning Tasks
Please email me for an easy AzureML task. Regression and Classification is needed in graphics. I will provide you details and pay you right away after we agree on the budget. email: burakkdedeoglu gmail.com
Thanks for your helps. I am looking forward to start.
-
Methods to remove Time Limit exceeded error from my code?
https://www.codechef.com/MARCH21C/problems/COLGLF4
This is the question, for which I have written the solution.
It shows Time Limit Exceeded(TLE) error.
Pls suggest how do I optimise it further.
I have optimised it to some extent. How do I Optimise it further. Pls Help!
Here in my code: e-> egg, h-> choclate
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #include <bits/stdc++.h> using namespace std; // help returns the min cost for n items int help(int n, int e, int h, int& a, int& b, int& c, int *** dp){ if(n==0) return 0; if(dp[h][e][n]!=-1) return dp[h][e][n]; int p1=INT_MAX,p2=INT_MAX,p3=INT_MAX; if(e>=2){ int ans = help(n-1,e-2,h,a,b,c,dp); // dp[h][e-2] = ans; if(ans != INT_MAX) p1=ans + a; } if(h>=3){ int ans = help(n-1,e,h-3,a,b,c,dp); // dp[h-3][e] = ans; if(ans != INT_MAX) p2 = ans + b; } if(e>=1&&h>=1){ int ans = help(n-1, e-1,h-1,a,b,c,dp); // dp[h-1][e-1] = ans; if(ans != INT_MAX) p3= ans + c; } int f = min(p1,min(p2,p3)); dp[h][e][n] = f; return f; } int main() { // your code goes here fastio(); int T; cin>>T; for(int t=0;t<T;t++){ int n,e,h,a,b,c; cin>>n>>e>>h>>a>>b>>c; // scanf("%d",&n); // scanf("%d",&e); // scanf("%d",&h); // scanf("%d",&a); // scanf("%d",&b); // scanf("%d",&c); int*** dp = new int**[h+1]; for(int i=0;i<=h;i++){ dp[i] = new int*[e+1]; for(int j=0;j<=e;j++){ dp[i][j] = new int[n+1]; for(int k=1;k<=n;k++) dp[i][j][k]=-1; } } for(int i=0;i<=h;i++){ for(int j=0;j<=e;j++){ dp[i][j][0]=0; } } int ans = help(n,e,h,a,b,c,dp); if(ans == INT_MAX) cout<<-1<<'\n'; else cout<<ans<<'\n'; // for(int i=0;i<=h;i++){ // for(int j=0;j<=e;j++){ // cout<<dp[i][j]<<" "; // }cout<<endl; // } for(int i=0;i<=h;i++){ for(int j=0;j<=e;j++){ delete [] dp[i][j]; } delete dp[i]; } delete [] dp; } return 0; }
-
Python Custom Config Files for Modules
I have below Directory Structure:
|-- masterFile.py
|-- firstFolder
|-- |-- first.py
|-- |-- configFile
|-- SecondFolder
|-- |-- second.py
|-- |-- configFileI have many folders like (firstFolder, secondFolder...) and all their python files have same type of code only difference is on processing the variables from config file. I have put all the common code in masterFile.py file and the variable processing has been kept in first.py,m second.py files as a function.
What I want to do is: I will run the masterFile.py file and depending on some input/signal I will call the fucntion from first.py, second.py .. file and I want them to be run with their own config file variables.
I am using below code format:
In first.py, second.py
import os import configparser config = configparser.ConfigParser() config.read(os.path.join(os.path.dirname(__file__),'config')) var1 = config['xyz']['abc'] var2 = config['jkl']['mno'] def doSomeMagic(INPUT_VAR): someProcessing_on var1, var2 & INPUT_VAR
Importing the modules in masterFile.py
from firstFolder import first from secondFolder import second initialization_of INPUT_VAR if SIGNAl == 1: first.doSomeMagic(INPUT_VAR)
Depending on some input/signal, I will call doSomeMagic function from first.py, second.py ... files. I want these function to use their config file but Config files are not accessible when I am following this format/structure. < br>
Any help on how to Achieve this and any advice to change these formats/stucture to make more Pythonic way.
I have some folder with name starting with a digit like: 7Yes
from 7Yes import 7yes
How can I import the python file from this directory?
-
Adopting code from Oddsportal URL to current & Next Page
I have a code that scrapes
https://www.oddsportal.com/soccer/england/premier-league/
odds and event data.
I want to adopt the same to get all data for "today" which is reflected at
https://www.oddsportal.com/matches/soccer/
and 'tomorrow' is
https://www.oddsportal.com/matches/soccer/20210309/
which is essentially
url/today+1
My current code that works is:
browser = webdriver.Chrome() browser.get("https://www.oddsportal.com/soccer/england/premier-league/") df = pd.read_html(browser.page_source, header=0)[0] dateList = [] gameList = [] home_odds = [] draw_odds = [] away_odds = [] for row in df.itertuples(): if not isinstance(row[1], str): continue elif ':' not in row[1]: date = row[1].split('-')[0] continue time = row[1] dateList.append(date) gameList.append(row[2]) home_odds.append(row[4]) draw_odds.append(row[5]) away_odds.append(row[6]) result = pd.DataFrame({'date': dateList, 'game': gameList, 'Home': home_odds, 'Draw': draw_odds, 'Away': away_odds})
Because the
datelist[]
is different to the links e.g.Algeria»Ligue 1
I am getting an errorNameError: name 'date' is not defined
How can I adopt the same to
https://www.oddsportal.com/matches/soccer/
and for
tomorrow
? -
How do I download an jsp file into a pdf with selenium?
I need to download the jsp inside of an iframe using selenium. It has to be in a pdf format.
How do I manage to do this?
<iframe id="miBody" name="miBody" src="/padron-puc-constancia-internet/jsp/Constancia.jsp" height="150%" width="100%" scrolling="auto" frameborder="0" marginwidth="0" marginheight="0" align="top" style="height: 629px;"></iframe>
-
Headless Chrome driver unable to fetch Instagram page in python Selenium driver
I tried to login and scrape a few details from my Instagram page in Python. I wanna do it in the headless mode because I'm going to deploy it in Heroku. So when I try to login using this code in the headless Chrome driver, the Instagram login page is not fetched. I have provided the screenshot also.
def login_insta(driver,username,password): driver.get("https://www.instagram.com/accounts/login") time.sleep(5) driver.save_screenshot('scrnsh.png') driver.find_element_by_xpath( "//input[@name='username']").send_keys(username) driver.find_element_by_xpath( "//input[@name='password']").send_keys(password) driver.find_element_by_xpath("//button/div[text()='Log In']").click() print("Logged in") options = Options() PATH = r"C:\Users\pcname\Downloads\chromedriver" options.add_argument("--headless") options.add_argument("--disable-dev-shm-usage") options.add_argument("--no-sandbox") options.add_argument('--disable-gpu') driver = webdriver.Chrome(executable_path=PATH, chrome_options=options) login_insta(driver,"name","pass")
The screenshot said "Error Please wait a few minutes before you try again" This error doesn't occur with the headlesss Firefox driver, I don't how to add Firefox buildpacks in Heroku. I have recent Chrome driver version. Please help me solve this issue.
Or if you can suggest buildpacks for Firefox for Heroku, and the steps to add them, it would be very helpful. Thank you!
-
React localhost3000 blank when compiled successfully
Terminal: npm start Compiled successfully! But the local host 3000: is blank On chrome browser What shall I do now?
-
How to Disable React Minified Error Messages?
I'm currently trying to figure out where an error is manifesting in my app, and am wondering how to change the minified chunks to function names with line numbers for local development.
Here are the messages I'm getting:
In my
server.js
file, I added the following code to try to resolve this:if(IS_LOCAL) { process.env.NODE_ENV = 'development'; }
Any help would be greatly appreciated!
-
How would I be able to input a string on a search bar?
I'm programming in C and got my program to open up a search engine (Microsoft Edge), but I still can't figure out how to get the user's input to be entered in the search bar. I'm wondering if there's an easy way to accomplish my goal?
Here's my code:
#include <stdlib.h> #include <string.h> #include <stdio.h> #include <unistd.h> #define size 100 int main(){ // Not sure if I should use (int argc, char **argv, char **envp) char input[size]; Printf("Please input your search!"); scanf("%s", &input); system("\"\"c:\\program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe\" \"www.google.com\"\""); return 0; }
-
Getting "Failed to load resource: net::ERR_HTTP2_PROTOCOL_ERROR" while running Python Selenium test scripts
I am running the test scripts with chrome browser using python selenium test scripts.
chromedriver = '.\\chromedriver.exe' options = webdriver.ChromeOptions() options.add_argument('--headless') options.add_argument('--incognito') options.add_argument('--disable-gpu') options.add_argument("--no-sandbox") options.add_argument('--ignore-certificate-errors') options.add_argument('window-size=1920x1080')
Cannot share the whole code but I have used sleep, implicit and explicit waits to slow down the webpage loads but still I am getting different failures in each time. The least errors I have seen is 6 out of 120 test cases and there is only 1 of them is a real failure. I thought about AJAX failure so I have added the waits mentioned above but still cannot trust the test scripts.
I am taking the screenshots of the failures and my only option would be to run the failed test cases one more time to see if they would pass.
Any suggestions are welcomed. Thank you for your time.
-
Selenium ChromeDriver Action and SendKeys don´t press the button
I have a problem with my SeleniumDriver and it drives me crazy. I almost tried every solution on stackoverflow..
My simple goal is to send a key to the browser, but not to an element. My key is "mediaTrackNext" and can be found at
Windows.Forms.Keys.MediaNextTrack
I tried almost any solution:
Dim actions As Actions = New Actions(TestBot) actions.SendKeys(Windows.Forms.Keys.MediaNextTrack).Perform()
or
TestBot.FindElement(By.XPath("/html/body")).SendKeys(Windows.Forms.Keys.MediaNextTrack)
or
Dim actions As Actions = New Actions(TestBot) actions.SendKeys(TestBot.FindElement(By.XPath("//body")), Keys.F12).Perform()
I can´t even send keys like F12 to open the developers console, nothing happens.. F5 doesn´t work as well. And yes, I tried a few Tags and xpaths, but no tag seem to work.
Is there another way? I am so stuck right now..
Thank you. Best regards, xored
-
Escping quotes in PHP regex
How can I find only the telephone number (1234827382) in the following string ($x)?
IMPORTANT: I used
htmlspecialchars()
function on$x
(text). Without useing this function the regex works. I need to find a regex solution when I usehtmlspecialchars()
before regex.font-size: 14px; color: #333;" >asd:</td> <td width="150" align="left" valign="top" bgcolor="#f5f5f5" style="padding: 6px; border: 1px solid #eaeaea;font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #333;" >Tel:</td> <td align="left" valign="top" style="padding: 6px; border: 1px solid #eaeaea;font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #333;" ><a href="tel:1234827382">1234827382</a></td> </tr> <tr> <td width="150" align="left"
I have tried:
$p = '/href="tel:12.{20}/'; preg_match_all($p, $x, $matchestel); print_r($matchestel);
If I try escape with \ then it also dont work:
$p = '/href=\"tel:12.{20}/';
If the text doesnt contain quote: <a href=tel:1234827382" (instead of this: <a href="tel:1234827382" ) then it finds, and after that I could remove the href" from the beginning. I know it is not the best solution. I think the problem is that I need to escape the " from pattern.
-
Several commands in one line for cronjob in hiera (Puppet) yaml
I have hieradata yaml file with a lot of options and some cronjobs I want to add one more cronjob that contain several bash commands in it with quotes:
hbase_test: cron: '*/5 * * * *' user: 'root' command: '(date && echo "describe \'my_table\'; exit" | hbase shell) >> hbase_test.log 2>&1;' flock: true
But this doesn't work - puppet fails to load such yaml. I also tried next way:
command: "(date && echo \"describe 'my_table'; exit\" | hbase shell) >> hbase_test.log 2>&1;"
Puppet is ok, hbase starts successfully, but fails:
describe my_table; exit NameError: undefined local variable or method `my_table' for #<Object:0xf9f041c>
The right command must be:
describe 'my_table'; exit
I lost quotes! And I don't know how to escape them in right way. I also tried
command:> (date && echo "describe 'my_table'; exit" | hbase shell) >> hbase_test.log 2>&1;
But cron doesn't start.
-
awk inside qsub: issues with awk $
Consider this working awk one-liner:
awk '$1 ~ /hello/' a.txt
. When I attempt to submit it to qsub, $1 is incorrectly recognized as a shell variable and replaced with empty space:awk ' ~ /hello/' a.txt
.I tried suggestions in Using awk with qsub and issues with quotations, including
\$1
andqsub -- awk '$1 ~ /hello/' a.txt
.Neither works.
I can certainly put awk in a script and call qsub that way, i.e.,
qsub awkscript.sh
. However, if there's a way to use qsub+awk from the command line, I'd like to learn how.